3

I have a JFrame-descendant window a with a JMenuBar and two components stored in a JPanel. One is a JTabbedPane, which occupies the majority of the screen, and the other is small JPanel that in turn contains a series of buttons. They are constructed as such:

//in constructor:
menubar = new BFIDEMenuBar(this);

setJMenuBar(menubar);

content = new JPanel();
add(content);

buttons = new BFIDEButtonBar();

editors = new JTabbedPane();

content.add(buttons, BorderLayout.NORTH);
content.add(editors, BorderLayout.CENTER);

When the window is smaller than a certain size, the components arranged as expected: the JTabbedPane occupying the center with the "buttons" JPanel centered above it: Looks good.

However, if the window is re-sized beyond a certain threshold, the JPanel changes location:

Not looking good.

Shrinking the window causes it to jump back to its previous (correct) position.

I have read the javadoc for BorderLayout and I have used it before, but I have yet to encounter this phenomenon. The javadoc says that "The NORTH and SOUTH components may be stretched horizontally;" but I don;t this counts as stretching.

No other methods are called from the constructor save for adding a few listeners and the obligatory setVisible, setEnabled, and the like.

Any thoughts on why this is happening or how to rectify it?

ApproachingDarknessFish
  • 14,133
  • 7
  • 40
  • 79

1 Answers1

4

JPanel by default uses a FlowLayout.

Try using

content = new JPanel(new BorderLayout());

instead

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366