This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Issues with null layout and setBounds  RSS feed

 
Ashish Schottky
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to Java Swing.

I am writing some simple swing programs which use null layout.
I want to get feel of swing, how to position them. I had rough time with Layouts, so tried using null layout.
As I am going to make this as an applet, I don't think that it is going to bother me much on resizing issues, please correct me if I am wrong or I am missing something.

My first code was to just fill up a rectangle, leaving 10px on each side.
Here is my code.

//My main class, which handles the visibility of the class, it doesnot involve any logic.



My second class contains the control panel, that is buttons, and over all display.


Here is my third part, where the it draws the figure.
I kept it all three differently because I wanted them to be independent of each other and my code doesnt become one lengthy mess.


I am confused with the setBound method.
I have set the size to be 500x500.
I have used setBound(10,10,480,480)
Doesn't this mean that I should get an rectangle filling the entire area of 480x480 and leaving 10px border on each side?
this is how I visualized

But rather I am getting this(image attached).
Its leaving proper 10 px from left and top, but then it covers more than the allowed area and doesnt give the visualized look.
What am I missing here?

pic.jpg
[Thumbnail for pic.jpg]
 
Rob Camick
Ranch Hand
Posts: 2752
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had rough time with Layouts


That is the proper approach.

so tried using null layout


And yet you are still having problems.

So spend time learning the proper approach and forget about the null layout.

Post your SSCCE that shows what you have done when using layout managers.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I want to get feel of swing, how to position them. I had rough time with Layouts, so tried using null layout.

if you want to dismiss one of Swing's great features, you might be better off learning Visual Basic.
 
Ashish Schottky
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for taking time to reply my question.
Here is what I was able to do, its simple tic-tac-toe problem, I have coded it using java swing, It will be great if you guys can play it and find flaws in it, also I would like you all to rate this and suggest improvements and also that I have just began to code swing.
Thank you.
applet
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!