Reputation: 3968
I want to display a two column layout in swing, a text label on the left and a button on the right. 80% width to be allocated to label and 20% width to be allocated to the button. Also, the number of rows are dynamic.
I have tried to use multiple layout managers, but none is working correctly. If I use the default layout, the label and the button move onto a single line if the applet is resized. If I use BorderLayout, the size of button becomes huge.
Code snippet:
this.contentPanel = new JPanel();
for (String eachParam : paramArrayList) {
JPanel pane = new JPanel();
JLabel lbl = new JLabel(eachParam);
JButton btn = new JButton();
btn.addActionListener(this);
btn.setText("Find");
btn.setName(eachParam);
pane.add(lbl);
pane.add(btn);
this.contentPanel.add(pane);
}
Upvotes: 2
Views: 718
Reputation: 1113
http://java.net/projects/tablelayout
I've used it many times, great layout.
Upvotes: 2