Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple Swing

 
Chris Stewart
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know the method I need to call on my objects (ComboBoxes and Labels) to set their position in the application GUI? Thanks!
Edit: Also, what would the code be to exit my application that I can put in an event listener? Thanks again!
[ April 16, 2002: Message edited by: Chris Stewart ]
 
Jeff Smith
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well if you aren't using a layout manager you'll need to call the setBounds() method on each component to set their size and location. Of course if you're using a layout manager then how you position the components will vary depending on the layout you're using.
And to exit your program you can use the System.exit method.
Jeff
 
Chris Stewart
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the exit method!
About the layout manager. I'm really not too sure what you mean. I'm setting the layout to FlowLayout.

I then go on to create my labels, comboboxes and buttons. I thought I would need to use setBounds but I wasn't sure. Do I need to use that?
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you allow the Layout Manager to handle positioning, you don't need to be concerned with it. It will determine where to place the component.
 
Chris Stewart
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there anyway I can do it myself? All of my comboboxes and labels are just lined up beside each other. It really looks terrible.
 
Jeff Smith
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I don't know how exacly you're trying to get the components lined up it's difficult to suggest a layout to use, but take a look at the javadoc for LayoutManager and LayoutManager2 and look through the lists of implementing classes. I'm sure there's one there that can do what you need. I personally use the GridBagLayout for nearly everything as it gives a great deal of control.
Jeff
 
Chris Stewart
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I changed it to use GridLayout for the manager. Making some progress now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic