Karsten Lentzsch wrote:
Right. I just like to add that there exist layout managers
that handle huge classes of screen design, for example
the ExplicitLayout, or even better the ExplicitLayout plus
Explicit Table Builder.
Ladies and gentlemen, I do believe we have a winner.
import com.zookitec.layout.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
public class LayoutProblem extends JFrame {
=09public static void main(String[] args) {
=09=09new LayoutProblem();
=09}
=09String columnNames[] = { "Column 1", "Column 2", "Column 3" };
=09String dataValues[][] = {
=09=09{ "0aa","bbb","ccc"}, { "0dd","eee","fff"}, { "0gg","hhh","iii"},
=09=09{ "1aa","bbb","ccc"}, { "1dd","eee","fff"}, { "1gg","hhh","iii"},
=09=09{ "2aa","bbb","ccc"}, { "2dd","eee","fff"}, { "2gg","hhh","iii"},
=09=09{ "3aa","bbb","ccc"}, { "3dd","eee","fff"}, { "3gg","hhh","iii"},
=09=09{ "4aa","bbb","ccc"}, { "4dd","eee","fff"}, { "4gg","hhh","iii"},
=09=09{ "5aa","bbb","ccc"}, { "5dd","eee","fff"}, { "5gg","hhh","iii"},
=09=09{ "6aa","bbb","ccc"}, { "6dd","eee","fff"}, { "6gg","hhh","iii"},
=09=09{ "7aa","bbb","ccc"}, { "7dd","eee","fff"}, { "7gg","hhh","iii"},
=09=09{ "8aa","bbb","ccc"}, { "8dd","eee","fff"}, { "8gg","hhh","iii"},
=09=09{ "9aa","bbb","ccc"}, { "9dd","eee","fff"}, { "9gg","hhh","iii"},
=09=09{ "aaa","bbb","ccc"}, { "ddd","eee","fff"}, { "ggg","hhh","iii"},
=09};
=09public LayoutProblem() {
=09=09JTable table;
=09=09JButton button1, button2, button3, button4;
=09=09JTextArea logArea;
=09=09setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
=09=09// table
=09=09table = new JTable(dataValues, columnNames);
=09=09table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
=09=09JScrollPane tableScrollPane = new JScrollPane(table);
=09=09// button panel
=09=09JPanel buttonPanel = new JPanel();
=09=09buttonPanel.setBorder(BorderFactory.createRaisedBevelBorder() );
=09=09SpringLayout buttonPanelLayout = new SpringLayout();
=09=09buttonPanel.setLayout(buttonPanelLayout);
=09=09final int PADDING = 6;
=09=09button1 = new JButton("Button 1");
=09=09buttonPanelLayout.putConstraint(SpringLayout.WEST, button1, PADDING,
SpringLayout.WEST, buttonPanel);
=09=09buttonPanelLayout.putConstraint(SpringLayout.NORTH, button1, PADDING,
SpringLayout.NORTH, buttonPanel);
=09=09buttonPanel.add(button1);
=09=09button2 = new JButton("Button 2");
=09=09buttonPanelLayout.putConstraint(SpringLayout.WEST, button2, PADDING,
SpringLayout.EAST, button1);
=09=09buttonPanelLayout.putConstraint(SpringLayout.NORTH, button2, PADDING,
SpringLayout.NORTH, buttonPanel);
=09=09buttonPanel.add(button2);
=09=09button3 = new JButton("Button 3");
=09=09buttonPanelLayout.putConstraint(SpringLayout.WEST, button3, PADDING,
SpringLayout.EAST, button2);
=09=09buttonPanelLayout.putConstraint(SpringLayout.NORTH, button3, PADDING,
SpringLayout.NORTH, buttonPanel);
=09=09buttonPanel.add(button3);
=09=09button4 = new JButton("Button 4");
=09=09buttonPanelLayout.putConstraint(SpringLayout.WEST, button4, PADDING,
SpringLayout.EAST, button3);
=09=09buttonPanelLayout.putConstraint(SpringLayout.NORTH, button4, PADDING,
SpringLayout.NORTH, buttonPanel);
=09=09buttonPanel.add(button4);
=09=09// text area
=09=09logArea = new JTextArea();
glad we could all help.