Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

TableLayout problem.  RSS feed

 
JohnAthon Bark
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a Swing GUI in Java using the TableLayout found here; http://java.sun.com/products/jfc/tsc/articles/tablelayout/

Currently I am stuck and need some help.

I have tried all sorts of code to get a JTextField of width 400 in the centre of the screen and below that a button which is 100 in width. So the button should be in the middle(as close as it can be) of the text feild but it just won't work.

I use TableLayout.PREFERRED and TableLayout.FILL constraints instead of the 0.54 etc.

Can someone show me how to do the above please?

 
Rob Camick
Ranch Hand
Posts: 2752
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know anything about TableLayout, but a common way to do layouts is to nest layout managers.

So you could create a JPanel with a FlowLayout that does center alignment. Then you add the button to the panel and add this panel you your table layout. Now the panel should occupy all the space of the cell, but the button will be in the middle of the panel.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!