1

I have a GUI with a JPanel and this panel adds 2 more panels. So I want one of this two panels to be in the highest quarter of the frame with a JComboBox and the other should be in the other 3 quarters of the frame and has a JTable in it. But with setBounds method I can't place them right I think because of the table.

If someone already had the same problem and could help me, that would be great.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
JUNGE
  • 73
  • 2
  • 8

1 Answers1

1

Not tested, but give this a try.

JPanel p1 = new JPanel();
int x = getWidth();
int y = getHeight() * 0.25;
int y2 = getHeight() * 0.75;
p1.setPreferredSize(new Dimension(x, y);
p1.add(yourFirsPanel);

JPanel p2 = new JPanel();
p2.setPreferredSize(new Dimension(x, y2);

JPanel p3 = new JPanel(new BorderLayout());
p3.add(p1, BorderLayout(NORTH));
p3.add(p2, BorderLayout(CENTER));
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
  • 1
    See [Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?](http://stackoverflow.com/q/7229226/418556) (**Yes.**) - OP Provide ASCII art of the GUI (or a drawing) as it should appear in smallest size and (if resizable) with extra width/height. – Andrew Thompson Oct 16 '13 at 09:39
  • @JUNGE not everthing that appears to solve a problem is a real solution :-) So, don't, your layout most probably will blow on the slightest change. Instead, use a suitable LayoutManager. – kleopatra Oct 16 '13 at 10:58