This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple Swing  RSS feed

 
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 ]
 
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?
 
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 SmithX
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.
 
Those are the largest trousers in the world! Especially when next to this ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!