开发者

Two panel layout in java (first panel has fix size, second has remainder size)

开发者 https://www.devze.com 2022-12-25 00:49 出处:网络
I want some like this: How make it ideologically 开发者_如何学编程correct?Your requirement seems to be a relatively simple use of BorderLayout.

I want some like this:

Two panel layout in java (first panel has fix size, second has remainder size)

How make it ideologically 开发者_如何学编程correct?


Your requirement seems to be a relatively simple use of BorderLayout.

The code snippet below assumes the panel are being added to a JFrame. Hence the getContentPane() calls.

javax.swing.JPanel jPanel1 = new javax.swing.JPanel();
javax.swing.JPanel jPanel2 = new javax.swing.JPanel();

jPanel1.setMaximumSize(new java.awt.Dimension(60, 32767));
jPanel1.setMinimumSize(new java.awt.Dimension(60, 100));
jPanel1.setPreferredSize(new java.awt.Dimension(60, 300));

getContentPane().add(jPanel1, java.awt.BorderLayout.WEST);

getContentPane().add(jPanel2, java.awt.BorderLayout.EAST);

Specify the maximum, minimum and preferred width of jPanel1 to be 60 px. Leave JPanel2 to "float".

If separation of the panes is required add a third pane of fixed width (say 5 px)

getContentPane().add(jPanel3, java.awt.BorderLayout.CENTER);
0

精彩评论

暂无评论...
验证码 换一张
取 消