Home Segments Top Top Previous Next

1093: Mainline

As you learned in Segment 919, the grid-layout manager lays out components on a regular grid. The following grid layout places components in two rows and three columns:

import java.awt.*; 
import javax.swing.*; 
public class TestPanel extends JPanel { 
 public TestPanel () { 
  setLayout(new GridLayout(2, 3)); 
  add(new TestButton("A")); 
  add(new TestButton("B")); 
  add(new TestButton("C")); 
  add(new TestButton("D")); 
  add(new TestButton("E")); 
  add(new TestButton("F")); 
 } 
}