Skip to content

Instantly share code, notes, and snippets.

@figengungor
Last active December 14, 2015 18:39
Show Gist options
  • Select an option

  • Save figengungor/5130658 to your computer and use it in GitHub Desktop.

Select an option

Save figengungor/5130658 to your computer and use it in GitHub Desktop.
Java GUI >> GridLayout
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class MyGUI extends JFrame {
JLabel jl1,jl2,jl3;
JButton jb1,jb2,jb3;
JPanel jp;
public MyGUI(){
setTitle("GridLayout Example");
setSize(300,300);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
jp = new JPanel();
jp.setLayout(new GridLayout(2,3)); //2 rows and 3 columns layout
jl1 = new JLabel("label 1");
jl2 = new JLabel("label 2");
jl3 = new JLabel("label 3");
jb1 = new JButton("button1");
jb2 = new JButton("button2");
jb3 = new JButton("button3");
jp.add(jl1);
jp.add(jl2);
jp.add(jl3);
jp.add(jb1);
jp.add(jb2);
jp.add(jb3);
add(jp);
}
public static void main(String [] args) {
new MyGUI();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment