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

Layout problem  RSS feed

 
Clemens Stich
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have already read through different articles about LayoutManagers, but I don't really understand them to get a proper layout... I want following simple layout:


I hope you understand. I want a table, then I want a label under that table (but with a little space between them) and then I want immeadiately after that label the textarea, and under that textarea I want two buttons.

Can anybody help me and give me an advice how to make this layout ? (which layoutmanagers to use etc... ?)
[ January 26, 2006: Message edited by: Clemens Stich ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your options are many, and it all depends on who gets what space.

eg
from your diagram, there are 2 'halves', so the contentPane could be a GridLayout(2,1)

top half is a JPanel(new BorderLayout())
JTable/scrollPane is added to BorderLayout.CENTER
(depending on overall size, you may want to add this to a holdingPanel,
so the holdingPanel takes additional space, then add holdingPanel to CENTER)
JLabel is added to another holdingPanel(new FlowLayout.LEFT/CENTER/RIGHT),
depending on where you want the label. This holdingPanel is added to SOUTH.

bottom half is also a JPanel(new BorderLayout())
textArea/scrollPane is added to BorderLayout.CENTER
(also may be better with a holdingPanel).
in the SOUTH is a JPanel(new GridLayout(1,2)).
again, depending on overall size, adding the buttons directly to the panel
might make them too big, if so, add each to a separate holdingPanel, then
add each holdingPanel to the GridLayout panel. These holdingPanels take the
extra space and allow the components to appear at their normal size. Only
problem is one button might be bigger than the other - can be fixed by
'padding' the text of the button e.g. buttons with "OK" and "Cancel" will be different widths, unless you make them " OK " and "Cancel"

Basically, a lot of trial and error

well, that didn't come out too good
" OK "
is supposed to be the same width as
"Cancel"

another go, code tags

[ January 26, 2006: Message edited by: Michael Dunn ]
[ January 26, 2006: Message edited by: Michael Dunn ]
 
Don Blodgett
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would use GridBagLayout with the following constraints given to each object:

scroller1:
gridx = 0;
gridy = 0;
gridwidth = 2;
gridheight = 4;

label:
gridx = 0;
gridy = 4;
gridwidth = 2;
insets = new Insets(16, 0, 0, 0);
// Change the 16 to another number if you want more/less space

scroller2:
gridx = 0;
gridy = 5;
gridwidth = 2;
gridheight = 4;

button1:
gridx = 0;
gridy = 6;

button2:
gridx = 1;
gridy = 6;

You may want to add insets to some of the constraints to give yourself some space around them. Especially the buttons as they are touching which, although there is nothing wrong with that, most programs have at least a small amount of space between them.
 
Clemens Stich
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both. I tried at first that with the GridBagLayout(well in fact I tried something similar before, but it didn't worked and that now also didn't worked... don't know why..).
Michael's suggestion worked properly, so thank you
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!