The GridLayout is a way of placing the components with great flexibility in the panel.
with setLayout (new GridLayout (row, column)); can set a layout with the number of rows and columns and components are added in defined cells.
The following example places the components in a grid that occupies the entire frame and places four buttons in their respective cell.
class Example extends JFrame {JButton
a = new JButton ("one");
two = new JButton JButton ("two");
JButton three = new JButton ("three");
JButton four = new JButton ("four");
Menu () {
this.setLayout (new GridLayout (2,2));
add (one);
add (two);
add (three);
add (four);
setTitle ("GridLayout Example");
setSize (400.400);
setVisible (true);}
public static void main (String [] args) {
new Example ();
}}
0 comments:
Post a Comment