• Post Reply Bookmark Topic Watch Topic
  • New Topic

Layout problem - somebody knows which LayoutManager to use?  RSS feed

 
Tina Boettger
Greenhorn
Posts: 15
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone!

I have a little layout problem. The general layout I use is
BorderLayout. I have components on top, bottom and in the center.
The centered component consists of four components.

There is a graph, the y and x axis and an empty box,
as you can see in the picture attached.
Now the y axis shouldn't stretch horizontally, the x axis
shouldn't vertically, the empty box shouldn't stretch at all
and all the rest of the space should be taken over by the graph.
Unlike buttons, the panels don't stretch automatically. Do I have
to calculate the preferred size of the items manually and pass
them on?

I tried using GridBagLayout which didn't work, and Borderlayout
just stretches above maximum size defined...

Maybe I am just way too much into it so I can't see clearly.
Somebody can see how to combine some extra Panels and
LayoutManagers to get what I want?

Thanks in advance!!
layout problem.png
[Thumbnail for layout problem.png]
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GridBagLayour should be fine. Note that you will need to set appropriate weightx and weighty: weightx = 0 for the first column (gridx=0) and weighty = 0 for the second row (gridy=1), and non-zero weightx for gridx=1, non-zero weighty for gridy=0. (Edit: and the concerned components should return a suitable Dimension from getPreferredSize.)

To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.

Don't forget to use the code tags so your code remains readable.
 
Rob Camick
Ranch Hand
Posts: 2752
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you also need to use the "fill" constraint. The Swing tutorial on How to Use GridBagLayout can explain it better than I can.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!