How to have a specific component resize based on available, visible space?
In my application, I have a layout similar to what is shown below:
@@@@@@@
XXXXXXX***
XXXXXXX***
XXXXXXX***
%%%%%%%
In this layout, X
is a JTable. The other components can remain the same size. Is there a layout or strategy that will have the JTable (X
) resize based开发者_JAVA百科 on available screen size and have everything else stay on the sides properly?
Thanks.
That looks very much like a BorderLayout to me. Have you tried that?
It can also be done with GroupLayout, but it is designed for GUI builders, as it's very verbose. So if you already have existing code, you might not want to try it first.
I am a big fan of JGoodies FormLayout. Here is some sample code of one way to do this with FormLayout.
JPanel panel = new JPanel();
FormLayout layout = new FormLayout("100dlu, 20dlu:grow", "pref, pref, pref");
panel.setLayout(layout);
JTextField t1 = new JTextField();
JTextField t2 = new JTextField();
JTable tb = new JTable();
JScrollPane sp = new JScrollPane();
sp.setViewportView(tb);
CellConstraints cc = new CellConstraints();
panel.add(t1, cc.xy(1, 1));
panel.add(t2, cc.xy(1, 3));
panel.add(sp, cc.xyw(1, 2, 2));
精彩评论