Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BorderLayout.NORTH behaving unexpecedly

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?

like image 590
ApproachingDarknessFish Avatar asked Oct 19 '25 05:10

ApproachingDarknessFish


1 Answers

JPanel by default uses a FlowLayout.

Try using

content = new JPanel(new BorderLayout());

instead

like image 69
MadProgrammer Avatar answered Oct 22 '25 03:10

MadProgrammer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!