-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
1.1.4
-
sparc
-
solaris_2.5
Name: asC58863 Date: 08/07/97
The java.awt.GridLayout.setColumns() method does not work.
This method should set the number of columns in this layout.
(see JavaDoc Comment )
" public void setColumns(int cols)
Sets the number of columns in this layout.
Parameters:
cols - number of columns in this layout"
Here is the test demonstrating the bug:
-----------------GridLayoutTest.java------------------------
import java.awt.*;
import java.awt.event.*;
public class GridLayoutTest {
public static void main( String argv[] ) {
GridLayoutTest test = new GridLayoutTest();
Panel testPanel = new Panel(); //step Construct test panel
testPanel.setLayout(new BorderLayout(5,5));
Panel gridPanel = new Panel(); //step Construct panel with GridLayout
gridPanel.setBackground(Color.white);
gridPanel.setLayout(new GridLayout(0, 1));
gridPanel.add(new Button("Button"));
gridPanel.add(new Label("Label")); //step Add some components
gridPanel.add(new TextField("TextField"));
gridPanel.add(new Checkbox("Checkbox"));
Choice choice = new Choice();
choice.add("Choice");
choice.add("Choice2");
choice.add("Choice3");
gridPanel.add(choice);
gridPanel.add(new Button("Another button"));
testPanel.add("Center", gridPanel);
Panel p = new Panel(); // steps create control panel
p.setLayout(new FlowLayout());
Button b1 = new Button("setRows");
p.add(b1);
TextField tf1 = new TextField("2", 2);
p.add(tf1);
TextField tf2 = new TextField("2", 2);
p.add(tf2);
Button b2 = new Button("setColumns");
p.add(b2);
GridLayoutListener listener = new GridLayoutListener(gridPanel, tf1, tf2);
b1.addActionListener(listener);
b2.addActionListener(listener);
testPanel.add("South", p);
Frame frame = new Frame("GridLayout creation Test");
frame.add(testPanel);
frame.setSize(500,300);
frame.setVisible(true);
}
}
class GridLayoutListener implements ActionListener {
Panel gridPanel;
TextField tf1, tf2;
GridLayoutListener(Panel gridPanel, TextField tf1, TextField tf2) {
this.gridPanel = gridPanel;
this.tf1 = tf1;
this.tf2 = tf2;
}
public void actionPerformed(ActionEvent e) {
String nameb = e.getActionCommand();
if(nameb.equals("setRows")) {
try {
int i1 = (new Integer(tf1.getText())).intValue();
GridLayout layout = (GridLayout)gridPanel.getLayout();
layout.setRows(i1);
gridPanel.setLayout(layout);
gridPanel.validate();
} catch (NumberFormatException E1) {
} catch (IllegalArgumentException e1) {
};
};
if(nameb.equals("setColumns")) {
try {
int i2 = (new Integer(tf2.getText())).intValue();
GridLayout layout = (GridLayout)gridPanel.getLayout();
layout.setColumns(i2);
gridPanel.setLayout(layout);
gridPanel.validate();
} catch (NumberFormatException E2) {
} catch (IllegalArgumentException e2) {
};
};
};
}
---------Output from the test---------------------
this test doesn't change the number of columns
--------------------------------------------------
======================================================================