List of usage examples for java.awt GridLayout GridLayout
public GridLayout(int rows, int cols, int hgap, int vgap)
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); URL url = new URL("http://www.java2s.com/style/download.png"); Image image = ImageIO.read(url); ImagePanel ip = new ImagePanel(new GridLayout(4, 4, 20, 20)); ip.setPreferredSize(new Dimension(640, 480)); f.setContentPane(ip);/*www . j av a 2 s . co m*/ f.pack(); f.setVisible(true); ip.setImage(new ImageIcon(image)); }
From source file:ActionButtonSample.java
public static void main(String args[]) { JFrame frame = new JFrame("DefaultButton"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { String command = actionEvent.getActionCommand(); System.out.println("Selected: " + command); }// w w w . j a v a 2 s .c o m }; frame.setLayout(new GridLayout(2, 2, 10, 10)); JButton button1 = new JButton("Text Button"); button1.setActionCommand("First"); button1.addActionListener(actionListener); frame.add(button1); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel gui = new JPanel(new BorderLayout(2, 2)); BufferedImage bi = new BufferedImage(600, 200, BufferedImage.TYPE_INT_RGB); gui.add(new JLabel(new ImageIcon(bi))); JFrame myframe = new JFrame(); JPanel myPanel = new JPanel(); gui.add(myPanel, BorderLayout.PAGE_END); myPanel.setLayout(new GridLayout(2, 0, 0, 0)); int x = 0;// w w w . j a va 2 s .c o m int y = 5; for (char alphabet = 'A'; alphabet <= 'Z'; alphabet++) { myPanel.add(new JButton(alphabet + "")); x++; if (x > 15) { y = 6; x = 0; } } myframe.add(gui); myframe.pack(); myframe.setVisible(true); myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:Main.java
public static void main(String[] args) { JPanel gui = new JPanel(new GridLayout(0, 1, 3, 15)); for (int ii = 1; ii < 4; ii++) { gui.add(getButtonLayout(ii));// w w w .ja va 2s . c o m } JOptionPane.showMessageDialog(null, gui); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame("Etched Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border raisedBorder = new EtchedBorder(EtchedBorder.RAISED); Border loweredBorder = new EtchedBorder(EtchedBorder.LOWERED); JButton raisedButton = new JButton("Raised"); raisedButton.setBorder(raisedBorder); JButton loweredButton = new JButton("Lowered"); loweredButton.setBorder(loweredBorder); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(1, 2, 5, 5)); contentPane.add(raisedButton);/*from w w w.jav a 2 s . c o m*/ contentPane.add(loweredButton); frame.setSize(300, 100); frame.setVisible(true); }
From source file:AnEtchedBorder.java
public static void main(String args[]) { JFrame frame = new JFrame("Etched Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border raisedBorder = new EtchedBorder(EtchedBorder.RAISED); Border loweredBorder = new EtchedBorder(EtchedBorder.LOWERED); JButton raisedButton = new JButton("Raised"); raisedButton.setBorder(raisedBorder); JButton loweredButton = new JButton("Lowered"); loweredButton.setBorder(loweredBorder); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(1, 2, 5, 5)); contentPane.add(raisedButton);/*from w w w .j av a 2 s. c o m*/ contentPane.add(loweredButton); frame.setSize(300, 100); frame.setVisible(true); }
From source file:AnEtchedBorder.java
public static void main(String args[]) { JFrame frame = new JFrame("Etched Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border raisedBorder = new EtchedBorder(EtchedBorder.RAISED); Border loweredBorder = new EtchedBorder(EtchedBorder.LOWERED); JButton raisedButton = new JButton("Raised"); raisedButton.setBorder(raisedBorder); JButton loweredButton = new JButton("Lowered"); loweredButton.setBorder(loweredBorder); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(1, 2, 5, 5)); contentPane.add(raisedButton);//from w ww . ja v a 2 s.c om contentPane.add(loweredButton); frame.setSize(300, 100); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { int BTN_COUNT = 3; int VERT_GAP = 10; int EB_GAP = 5; float TITLE_SIZE = 36f; String TITLE_TEXT = "This is my Title"; JLabel titleLabel = new JLabel(TITLE_TEXT, SwingConstants.CENTER); titleLabel.setFont(titleLabel.getFont().deriveFont(TITLE_SIZE)); JPanel titlePanel = new JPanel(); titlePanel.add(titleLabel);//from ww w.j a v a 2 s .c o m JPanel buttonPanel = new JPanel(new GridLayout(1, 0, 5, 0)); for (int i = 0; i < BTN_COUNT; i++) { JButton btn = new JButton("Button " + (i + 1)); buttonPanel.add(btn); } JTextArea textArea = new JTextArea(20, 30); JPanel mainPanel = new JPanel(); mainPanel.setBorder(BorderFactory.createEmptyBorder(EB_GAP, EB_GAP, EB_GAP, EB_GAP)); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS)); mainPanel.add(titlePanel); mainPanel.add(Box.createVerticalStrut(VERT_GAP)); mainPanel.add(buttonPanel); mainPanel.add(Box.createVerticalStrut(VERT_GAP)); mainPanel.add(new JScrollPane(textArea)); JFrame frame = new JFrame(); frame.getContentPane().add(mainPanel, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[] data = { "alist", "arithmetic", "ASCIInumbers", "A", "B", "list", "C", "D", "E", "numeral", "G", "F" }; JCheckBox[] checkBox;/*from w ww. j ava 2s . c o m*/ JButton submitButton; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); JPanel contentPane = new JPanel(); contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(5, 5)); checkBox = new JCheckBox[data.length]; JPanel centerPanel = new JPanel(); centerPanel.setLayout(new GridLayout(0, 4, 5, 5)); for (int i = 0; i < data.length; i++) { checkBox[i] = new JCheckBox(data[i]); centerPanel.add(checkBox[i]); } contentPane.add(centerPanel, BorderLayout.CENTER); JPanel footerPanel = new JPanel(); submitButton = new JButton("Submit"); footerPanel.add(submitButton); contentPane.add(footerPanel, BorderLayout.PAGE_END); frame.setContentPane(contentPane); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel gui = new JPanel(new BorderLayout()); gui.setBorder(new EmptyBorder(2, 3, 2, 3)); JPanel textPanel = new JPanel(new BorderLayout(5, 5)); textPanel.add(new JScrollPane(new JTextArea("Top Text", 3, 20)), BorderLayout.PAGE_START); textPanel.add(new JScrollPane(new JTextArea("Main Text", 10, 10))); gui.add(textPanel, BorderLayout.CENTER); JPanel buttonCenter = new JPanel(new GridBagLayout()); buttonCenter.setBorder(new EmptyBorder(5, 5, 5, 5)); JPanel buttonPanel = new JPanel(new GridLayout(0, 1, 5, 5)); for (int ii = 1; ii < 6; ii++) { buttonPanel.add(new JButton("Button " + ii)); }//from www. ja va 2s . co m buttonCenter.add(buttonPanel); gui.add(buttonCenter, BorderLayout.LINE_END); JFrame f = new JFrame("Demo"); f.add(gui); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setLocationByPlatform(true); f.pack(); f.setVisible(true); }