Vote count:
0
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class GridLayoutTest {
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("GridLayout Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new GridLayout(3, 2));
frame.add(new JButton("Button 1"));
frame.add(new JButton("Button 2"));
frame.add(new JButton("Button 3"));
frame.add(new JButton("Button 4"));
frame.add(new JButton("Button 5"));
frame.add(new JButton("Button 6"));
frame.add(new JButton("Button 7"));
frame.add(new JButton("Button 8"));
frame.pack();
frame.setVisible(true);
}
}
I got the code from this tutorial website: http://ift.tt/1et1vM4
This program displays 8 buttons on the screen. I'm having trouble understanding the layout. Notice that row=3, and column=2. When I run the program, the arrangement of the button is row=3 and column=3....
Changing the number of rows actually changes the layout, but changing the number of columns doesn't changes the layout and the number of column will always remain as 2. Why is that?
asked 33 secs ago
JFrame - Setting the Row and Column in a GridLayout
Aucun commentaire:
Enregistrer un commentaire