Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Swing components  RSS feed

 
Roberto Diaz
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 3 swing components text field, combo box and a text field and want to display them in that order each on one line.
I am not able to figure out Swing equivalent of text new line.
I tried fiddling with Layout manager, but I think I am doing something wrong.
Any ideas or pointers would be helpful.
Thanks
 
G Estes
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several approaches. You should add these components to a container of some kind (try a JPanel). For three items, you can set the layout to BorderLayout and add each one to a different region (there are 5 - North, South, East, West and Center)...
Try something like this:
JPanel panel = new JPanel(new BorderLayout());
panel.add(myTextField1, BorderLayout.NORTH);
panel.add(myCombo, BorderLayout.CENTER);
panel.add(myTextField2, BorderLayout.SOUTH);


Be sure to add the panel to your JFrame with
getContentPane().add(panel);
pack();
show();
Hope this helps...
[ October 30, 2002: Message edited by: Gil Estes ]
 
Roberto Diaz
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Works just fine.
Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!