J
Jenny
Hi,
According to API,
public GridLayout(int rows,
int cols,
int hgap,
int vgap)Creates a grid layout with the specified
number of rows and columns. All components in the layout are given
equal size.
In addition, the horizontal and vertical gaps are set to the specified
values. Horizontal gaps are placed at the left and right edges, and
between each of the columns. Vertical gaps are placed at the top and
bottom edges, and between each of the rows.
But if you run the code below, GridLayout does not leave room between
edge of window and objects. Is this a bug? Thanks.
import javax.swing.*;
import java.awt.*;
public class WindowGridLayout {
public static void main(String[] args) {
JFrame f = new JFrame("hello");
f.setSize(400, 400);
f.setLocation(100, 100);
JLabel u= new JLabel("User Name");
JTextField user = new JTextField(8);
JLabel p= new JLabel("Password");
JPasswordField password = new JPasswordField(10);
password.setEchoChar('#');
GridLayout grd = new GridLayout(3,2,50,50);
Container pane = f.getContentPane();
pane.setLayout(grd);
pane.add(u);
pane.add(user);
pane.add(p);
pane.add(password);
JTextArea a = new JTextArea(3,8);
a.insert("test \none",0);
pane.add(a);
f.setVisible(true);
}}
According to API,
public GridLayout(int rows,
int cols,
int hgap,
int vgap)Creates a grid layout with the specified
number of rows and columns. All components in the layout are given
equal size.
In addition, the horizontal and vertical gaps are set to the specified
values. Horizontal gaps are placed at the left and right edges, and
between each of the columns. Vertical gaps are placed at the top and
bottom edges, and between each of the rows.
But if you run the code below, GridLayout does not leave room between
edge of window and objects. Is this a bug? Thanks.
import javax.swing.*;
import java.awt.*;
public class WindowGridLayout {
public static void main(String[] args) {
JFrame f = new JFrame("hello");
f.setSize(400, 400);
f.setLocation(100, 100);
JLabel u= new JLabel("User Name");
JTextField user = new JTextField(8);
JLabel p= new JLabel("Password");
JPasswordField password = new JPasswordField(10);
password.setEchoChar('#');
GridLayout grd = new GridLayout(3,2,50,50);
Container pane = f.getContentPane();
pane.setLayout(grd);
pane.add(u);
pane.add(user);
pane.add(p);
pane.add(password);
JTextArea a = new JTextArea(3,8);
a.insert("test \none",0);
pane.add(a);
f.setVisible(true);
}}