gridLayout doesn't work r
To: comp.lang.java.gui
I am new to java.swing and its layout programming. I encounter a
strange problem when I use the boxLayout in a
base panel and gridLayout in each sub panel.
as you can see, I set the boxLayout in the base panel in vertical
fashion ( setJcontentPane() ). inside each box I use the gridLaout to
addbuttons. There are two boxes in the panel. The first one is for
user, the second one is for company. When you call the initialize()
the UI is built.
Inside the user box ( setManageUserPanel() ), the gridLayout is set to
(1, 3, 10 ,20)
Inside the company box ( setManageCompanyPanel() ), the gridLayout is
set to (2, 3, 10, 20)
The problem is in the company box, the buttons are diplay in two rows
and each row has two buttons.
1--2,
3--4,
Should it be in two rows but first row has three buttons and second
row has only one?
1--2--3,
4
Also here are what I change the gridLayout for the company box, below
are how the button get display
(4, 1, 10, 20) correct
1--,
2--,
3--,
4--,
(1, 4, 10, 20) correct
1--2--3--4
(2, 4, 10, 20) NOT RIGHT!!!
1--2,
3--4,
don't what's wrong of my code, the gridLayout doesn't do what it
suppose to do. Please help
private void initialize() {
this.setSize(1024, 768);
this.setJContentPane();
JScrollPane scrollPane = new JScrollPane
( ScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
ScollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setViewportView(this.jContentPane);
this.setContentPane(scrollPane);
this.setTitle("Administration");
}
private void setJContentPane() {
this.jContentPane = new JPanel();
this.jContentPane.setPreferredSize(new Dimension(1024, 900));
Box adminPanelBoxes[] = new Box[2];
for(int i=0; i<adminPanelBoxes.length; i++)
adminPanelBoxes[i] = Box.createVerticalBox();
this.setManageUserPanel();
adminPanelBoxes[0].add(this.manageUserPanel);
this.jContentPane.add(adminPanelBoxes[0]);
this.setManageCompanyPanel();
adminPanelBoxes[1].add(this.manageCompanyPanel);
this.jContentPane.add(adminPanelBoxes[1]);
}
private void setManageUserPanel() {
this.manageUserPanel = new JPanel();
this.manageUserPanel.setLayout( new GridLayout(1, 3, 10, 20) );
this.manageUserPanel.setPreferredSize(new Dimension(960, 100));
this.manageUserPanel.add( new JButton("button") );
this.manageUserPanel.add( new JButton("button");
this.manageUserPanel.add( new JButton("button");
this.manageUserPanel.setBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Border 1"),
BorderFactory.createEmptyBorder(5, 5, 5, 5)));
}
private void setManageCompanyPanel() {
this.manageFilterPanel = new JPanel();
this.manageFilterPanel.setLayout( new GridLayout(2, 3, 10, 20) );
this.manageFilterPanel.setPreferredSize(new Dimension(960, 200));
this.manageFilterPanel.add( new JButton("button") );
this.manageFilterPanel.add( new JButton("button") );
this.manageFilterPanel.add( new JButton("button") );
this.manageFilterPanel.add( new JButton("button") );
this.manageFilterPanel.setBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Border 2"),
BorderFactory.createEmptyBorder(5, 5, 5, 5)));
}
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24