简体   繁体   中英

Java Swing Custom Layout Issue

I'm having trouble organizing the contents of a JPanel. I've tried different layout managers but haven't gotten anything to work.

The JPanel contains 3 other JPanels and should look like this:

所需的布局

Does anyone know how I can achieve this layout?

Thanks in advance.

What you want is similar to a BorderLayout , but using one natively will cause the second pane to fill the bottom space (rather than the 3rd pane.)

However, you could use two in tandem to get this effect - The first BorderLayout pane would contain the second BorderLayout pane (in its centre) and panel 3 (on its east.)

In the second BorderLayout pane, you could then just set pane 1 to be the centre, and pane 2 to be the south.

Simplest, but not best solution, is to use null Layout Manager with manually set components bounds. It is called Absolute Positioning

Other approach is to use horizontal SplitPane with nested Vertical SplitPane: left one will contain vertical splitPane with Panel1 and Panel2, and right will be just Panel3.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM