List of usage examples for java.awt GridLayout GridLayout
public GridLayout(int rows, int cols)
From source file:FocusCycleSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Focus Cycle Sample"); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(3, 3)); for (int i = 0; i < 8; i++) { JButton button = new JButton("" + i); contentPane.add(button);/*w w w .ja va 2 s. com*/ } JPanel panel = new FocusCycleConstrainedJPanel(); panel.setLayout(new GridLayout(1, 3)); for (int i = 0; i < 3; i++) { JButton button = new JButton("" + (i + 3)); panel.add(button); } contentPane.add(panel); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); JPanel panel = new JPanel(); Container c = frame.getContentPane(); panel.setSize(100, 100);//from w w w. j av a 2 s. com panel.setLayout(new GridLayout(1000, 1)); for (int i = 0; i < 1000; i++) panel.add(new JLabel("JLabel " + i)); JScrollPane jsp = new JScrollPane(panel); c.add(jsp); frame.setSize(100, 100); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); int x = 5;/*from w ww . j a v a 2 s.com*/ int y = 5; JPanel panel = new JPanel(); panel.setLayout(new GridLayout(x, y)); for (int i = 0; i < x * y; i++) { JButton button = new JButton(String.valueOf(i)); button.setPreferredSize(new Dimension(100, 100)); panel.add(button); } JPanel container = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0)); container.add(panel); JScrollPane scrollPane = new JScrollPane(container); f.getContentPane().add(scrollPane); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("GridLayout"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new GridLayout(3, 0)); for (int i = 1; i <= 9; i++) { buttonPanel.add(new JButton("Button " + i)); }/* www . j a v a 2s . com*/ contentPane.add(buttonPanel, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:SampleProgress.java
public static void main(String args[]) { JFrame frame = new JFrame("ProgressMonitor Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(0, 1)); JButton startButton = new JButton("Start"); ActionListener startActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component parent = (Component) actionEvent.getSource(); monitor = new ProgressMonitor(parent, "Loading Progress", "Getting Started...", 0, 200); progress = 0;/*from w w w.ja v a 2s.c o m*/ } }; startButton.addActionListener(startActionListener); frame.add(startButton); JButton increaseButton = new JButton("Manual Increase"); ActionListener increaseActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { if (monitor == null) return; if (monitor.isCanceled()) { System.out.println("Monitor canceled"); } else { progress += 5; monitor.setProgress(progress); monitor.setNote("Loaded " + progress + " files"); } } }; increaseButton.addActionListener(increaseActionListener); frame.add(increaseButton); JButton autoIncreaseButton = new JButton("Automatic Increase"); ActionListener autoIncreaseActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { if (monitor != null) { if (timer == null) { timer = new Timer(250, new ActionListener() { public void actionPerformed(ActionEvent e) { if (monitor == null) return; if (monitor.isCanceled()) { System.out.println("Monitor canceled"); timer.stop(); } else { progress += 3; monitor.setProgress(progress); monitor.setNote("Loaded " + progress + " files"); } } }); } timer.start(); } } }; autoIncreaseButton.addActionListener(autoIncreaseActionListener); frame.add(autoIncreaseButton); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Label Text Pos"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(2, 2)); Border border = LineBorder.createGrayLineBorder(); Icon warnIcon = MetalIconFactory.getTreeComputerIcon(); JLabel label1 = new JLabel(); label1.setText("Left-Bottom"); label1.setHorizontalTextPosition(JLabel.LEFT); label1.setVerticalTextPosition(JLabel.BOTTOM); label1.setBorder(border);// w ww. j ava 2 s .c o m frame.add(label1); JLabel label2 = new JLabel(warnIcon); label2.setText("Right-TOP"); label2.setHorizontalTextPosition(JLabel.RIGHT); label2.setVerticalTextPosition(JLabel.TOP); label2.setBorder(border); frame.add(label2); JLabel label3 = new JLabel(warnIcon); label3.setText("Center-Center"); label3.setHorizontalTextPosition(JLabel.CENTER); label3.setVerticalTextPosition(JLabel.CENTER); label3.setBorder(border); frame.add(label3); JLabel label4 = new JLabel(warnIcon); label4.setText("Center-Bottom"); label4.setHorizontalTextPosition(JLabel.CENTER); label4.setVerticalTextPosition(JLabel.BOTTOM); label4.setBorder(border); frame.add(label4); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Label Text Pos"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(2, 2)); Border border = LineBorder.createGrayLineBorder(); Icon warnIcon = MetalIconFactory.getTreeComputerIcon(); JLabel label1 = new JLabel(warnIcon); label1.setText("Left-Bottom"); label1.setHorizontalTextPosition(JLabel.LEFT); label1.setVerticalTextPosition(JLabel.BOTTOM); label1.setBorder(border);/*from w w w .j a v a 2s . c o m*/ frame.add(label1); JLabel label2 = new JLabel(warnIcon); label2.setText("Right-TOP"); label2.setHorizontalTextPosition(JLabel.RIGHT); label2.setVerticalTextPosition(JLabel.TOP); label2.setBorder(border); frame.add(label2); JLabel label3 = new JLabel(warnIcon); label3.setText("Center-Center"); label3.setHorizontalTextPosition(JLabel.CENTER); label3.setVerticalTextPosition(JLabel.CENTER); label3.setBorder(border); frame.add(label3); JLabel label4 = new JLabel(warnIcon); label4.setText("Center-Bottom"); label4.setHorizontalTextPosition(JLabel.CENTER); label4.setVerticalTextPosition(JLabel.BOTTOM); label4.setBorder(border); frame.add(label4); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { List<Phone> phones = new ArrayList<>(); phones.add(new Phone("Galaxy", 12345)); phones.add(new Phone("iPhone", 12345)); JPanel panel = new JPanel(new GridLayout(0, 1)); for (Phone phone : phones) { String html = "<html><body style='width:100px'>Phone: " + phone.getName() + "<br/>Model: " + phone.getModel() + "</body></html>"; JLabel label = new JLabel(html); label.setBorder(new MatteBorder(0, 0, 1, 0, Color.BLACK)); panel.add(label);// w w w .ja v a 2 s .c om } JOptionPane.showMessageDialog(null, panel, "Phone List", JOptionPane.PLAIN_MESSAGE); }
From source file:JPasswordFieldTest.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setTitle("JTextField Test"); frame.setLayout(new GridLayout(2, 2)); JLabel label = new JLabel("User Name:", SwingConstants.RIGHT); JLabel label2 = new JLabel("Password:", SwingConstants.RIGHT); JTextField userNameField = new JTextField(20); JPasswordField passwordField = new JPasswordField(); frame.add(label);/*from w w w . j ava2s .c o m*/ frame.add(userNameField); frame.add(label2); frame.add(passwordField); frame.setSize(200, 70); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JLabel label = new JLabel("java2s.com"); JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(label);//from ww w . j a v a2s. c o m JPanel buttons = new JPanel(new GridLayout(0, 1)); for (int index = 0; index < 10; index++) { buttons.add(new JButton(String.valueOf(index))); } JPanel right = new JPanel(new BorderLayout()); right.add(buttons, BorderLayout.NORTH); frame.add(right, BorderLayout.EAST); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }