List of usage examples for java.awt GridLayout GridLayout
public GridLayout(int rows, int cols)
From source file:TextForm.java
public TextForm(String[] labels, char[] mnemonics, int[] widths, String[] tips) { super(new BorderLayout()); JPanel labelPanel = new JPanel(new GridLayout(labels.length, 1)); JPanel fieldPanel = new JPanel(new GridLayout(labels.length, 1)); add(labelPanel, BorderLayout.WEST); add(fieldPanel, BorderLayout.CENTER); fields = new JTextField[labels.length]; for (int i = 0; i < labels.length; i += 1) { fields[i] = new JTextField(); if (i < tips.length) fields[i].setToolTipText(tips[i]); if (i < widths.length) fields[i].setColumns(widths[i]); JLabel lab = new JLabel(labels[i], JLabel.RIGHT); lab.setLabelFor(fields[i]);/* w ww .jav a 2s . c o m*/ if (i < mnemonics.length) lab.setDisplayedMnemonic(mnemonics[i]); labelPanel.add(lab); JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT)); p.add(fields[i]); fieldPanel.add(p); } }
From source file:Main.java
public Main() { setSize(300, 300);//from ww w . j a v a2s . co m setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel controlPane = new JPanel(new GridLayout(2, 1)); controlPane.setOpaque(false); controlPane.add(new JLabel("Please wait...")); controlPane.add(waiter); glass.setOpaque(false); glass.add(padding); glass.add(new JLabel()); glass.add(controlPane); glass.add(new JLabel()); glass.add(new JLabel()); glass.setSize(new Dimension(300, 300)); setGlassPane(glass); JButton startB = new JButton("Start!"); startB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent A) { glass.setVisible(true); padding.requestFocus(); } }); Container contentPane = getContentPane(); contentPane.add(startB, BorderLayout.SOUTH); }
From source file:Main.java
Main() { setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(900, 600);//from w ww .ja v a 2s .c o m JPanel left = new JPanel(); left.setBackground(Color.BLUE); JPanel right = new JPanel(new BorderLayout()); JLabel fox = new JLabel("The quick brown fox jumps over the lazy dog."); fox.setFont(new Font(null, 0, 50)); JPanel rightBottom = new JPanel(); rightBottom.setLayout(new GridLayout(10, 10)); for (int i = 1; i <= 100; i++) { rightBottom.add(new JButton("butt" + i)); } right.add(fox, BorderLayout.NORTH); right.add(rightBottom, BorderLayout.CENTER); add(right); }
From source file:Main.java
public Main() { this.setDefaultCloseOperation(EXIT_ON_CLOSE); // Make sure the frame is undecorated this.setUndecorated(true); this.setBackground(new Color(0, 0, 0, 0)); this.setSize(200, 200); // Center it on the screen this.setLocationRelativeTo(null); this.getContentPane().setLayout(new GridLayout(0, 1)); this.add(new TranslucentJPanel(Color.RED)); JButton closeButton = new JButton("Close"); this.add(closeButton); closeButton.addActionListener(e -> System.exit(0)); }
From source file:Main.java
void initContainer(Container container) { container.setLayout(new GridLayout(1, 0)); buttonPanel = new JPanel(new GridLayout(0, 1)); Object[] menuNames = { "ROOT", new Object[] { "A", new Object[] { "CSS", "HTML", "SQL", "Java" }, "Code", new Object[] { "Test", "S", "C" } }, new Object[] { "Code 1", new Object[] { "A", "I", "H", "O" }, "Code", new Object[] { "P", "S", "C" }, "C" } }; DefaultMutableTreeNode currentNode = processHierarchy(menuNames); menuTree = new JTree(currentNode); menuTree.setVisibleRowCount(10);/*from w w w . j av a 2 s . c o m*/ menuTree.expandRow(2); initializeButtons(currentNode); container.add(buttonPanel, BorderLayout.WEST); container.add(new JScrollPane(menuTree), BorderLayout.EAST); menuTree.addTreeSelectionListener(e -> { initializeButtons((DefaultMutableTreeNode) menuTree.getLastSelectedPathComponent()); }); }
From source file:Main.java
public Main() { setSize(500, 500);//ww w . ja v a 2 s. c o m setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setLayout(new GridLayout(0, 1)); JPanel buttonPanel = new JPanel(); JButton addButton = new JButton("add"); addButton.addActionListener(e -> addElementToArrayList()); JButton removeButton = new JButton("remove"); removeButton.addActionListener(e -> removeElementFromArrayList()); tabbedPane = new JTabbedPane(); tabbedPaneMouseListener = (new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { if (e.getClickCount() == 1) { System.out.println("Do Something"); } } } }); tabbedPane.addMouseListener(tabbedPaneMouseListener); buttonPanel.add(addButton); buttonPanel.add(removeButton); add(buttonPanel); this.add(tabbedPane); }
From source file:Main.java
public Main() { frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocation(150, 150);//from www . j av a 2 s. c om frame.setLayout(new GridLayout(0, 1)); frame.add(reset); frame.add(jtf1); frame.add(jtf2); frame.add(jtf3); frame.add(jtf4); frame.add(combo); this.initFields(); reset.addActionListener(e -> { initFields(); }); for (Edit e : Edit.values()) { combo.addItem(e); } combo.setSelectedIndex(jtf1.getFocusLostBehavior()); combo.addActionListener(e -> { Edit current = (Edit) combo.getSelectedItem(); jtf1.setFocusLostBehavior(current.getValue()); }); frame.pack(); frame.setVisible(true); }
From source file:SwingSpinnerTest.java
public SwingSpinnerTest() { super("JSpinner Test"); setSize(300, 180);/*from w w w .jav a 2 s . c o m*/ setDefaultCloseOperation(EXIT_ON_CLOSE); Container c = getContentPane(); c.setLayout(new GridLayout(0, 2)); c.add(new JLabel(" Basic Spinner")); c.add(new JSpinner()); c.add(new JLabel(" Date Spinner")); c.add(new JSpinner(new SpinnerDateModel())); String weekdays[] = new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; c.add(new JLabel(" List Spinner")); c.add(new JSpinner(new SpinnerListModel(weekdays))); c.add(new JLabel(" Number Spinner")); c.add(new JSpinner(new SpinnerNumberModel(0, 0, 100, 5))); c.add(new JLabel(" Rollover List Spinner")); c.add(new JSpinner(new RolloverSpinnerListModel(weekdays))); setVisible(true); }
From source file:FocusTraversalExample.java
public FocusTraversalExample() { setLayout(new GridLayout(6, 1)); JButton button1 = new JButton("Texas"); JButton button2 = new JButton("Vermont"); JButton button3 = new JButton("Florida"); JButton button4 = new JButton("Alabama"); JButton button5 = new JButton("Minnesota"); JButton button6 = new JButton("California"); setBackground(Color.lightGray); add(button1);/*from ww w.j a va2s.c o m*/ add(button2); add(button3); add(button4); add(button5); add(button6); }
From source file:Main.java
public Main() { comboBox.addItem("One"); comboBox.addItem("Two"); comboBox.addItem("Three"); JButton button = new JButton("Show Selected"); button.addActionListener(e -> System.out.println("Selected item: " + comboBox.getSelectedItem())); JButton button1 = new JButton("Append Items"); button1.addActionListener(e -> appendCbItem()); JButton button2 = new JButton("Reduce Items"); button2.addActionListener(e -> reduceCbItem()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(4, 1)); frame.add(comboBox);//from ww w . ja va2s . c o m frame.add(button); frame.add(button1); frame.add(button2); frame.pack(); frame.setVisible(true); selectFirstItem(); }