List of usage examples for java.awt GridLayout GridLayout
public GridLayout(int rows, int cols)
From source file:FlatCheckBox.java
public static void main(String args[]) { JFrame frame = new JFrame("Flat CheckBox Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Pizza Toppings"); panel.setBorder(border);// w ww . j a va 2 s.co m JCheckBox check = new JCheckBox("Anchovies"); check.setBorderPaintedFlat(true); panel.add(check); check = new JCheckBox("Garlic"); panel.add(check); check = new JCheckBox("Onions"); check.setBorderPaintedFlat(true); panel.add(check); check = new JCheckBox("Pepperoni"); panel.add(check); check = new JCheckBox("Spinach"); check.setBorderPaintedFlat(true); panel.add(check); JButton button = new JButton("Submit"); Container contentPane = frame.getContentPane(); contentPane.add(panel, BorderLayout.CENTER); contentPane.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Grouping Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); ButtonGroup group = new ButtonGroup(); JRadioButton aRadioButton = new JRadioButton("A"); JRadioButton bRadioButton = new JRadioButton("B"); ActionListener crustActionListener = new ActionListener() { String lastSelected;// ww w .j a va 2 s .co m public void actionPerformed(ActionEvent actionEvent) { AbstractButton aButton = (AbstractButton) actionEvent.getSource(); String label = aButton.getText(); String msgStart; if (label.equals(lastSelected)) { msgStart = "Reselected: "; } else { msgStart = "Selected: "; } lastSelected = label; System.out.println(msgStart + label); } }; panel.add(aRadioButton); group.add(aRadioButton); panel.add(bRadioButton); group.add(bRadioButton); aRadioButton.addActionListener(crustActionListener); bRadioButton.addActionListener(crustActionListener); frame.add(panel); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Reverse Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(3, 3)); for (int i = 0; i < 9; i++) { JButton button = new JButton(Integer.toString(i)); frame.add(button);// w ww.jav a 2 s. co m } final Container contentPane = frame.getContentPane(); Comparator<Component> comp = new Comparator<Component>() { public int compare(Component c1, Component c2) { Component comps[] = contentPane.getComponents(); List list = Arrays.asList(comps); int first = list.indexOf(c1); int second = list.indexOf(c2); return second - first; } }; FocusTraversalPolicy policy = new SortingFocusTraversalPolicy(comp); frame.setFocusTraversalPolicy(policy); frame.setSize(300, 200); frame.setVisible(true); }
From source file:JRadioButtonActionListener.java
public static void main(String args[]) { JFrame frame = new JFrame("Grouping Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); ButtonGroup group = new ButtonGroup(); JRadioButton aRadioButton = new JRadioButton("A"); JRadioButton bRadioButton = new JRadioButton("B"); ActionListener sliceActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { AbstractButton aButton = (AbstractButton) actionEvent.getSource(); System.out.println("Selected: " + aButton.getText()); }//w w w .j av a 2s . co m }; panel.add(aRadioButton); group.add(aRadioButton); panel.add(bRadioButton); group.add(bRadioButton); aRadioButton.addActionListener(sliceActionListener); bRadioButton.addActionListener(sliceActionListener); frame.add(panel); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Reverse Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(3, 3)); for (int i = 9; i > 0; i--) { JButton button = new JButton(Integer.toString(i)); frame.add(button, 0);//from w w w . j ava 2 s . com } final Container contentPane = frame.getContentPane(); Comparator<Component> comp = new Comparator<Component>() { public int compare(Component c1, Component c2) { Component comps[] = contentPane.getComponents(); List list = Arrays.asList(comps); int first = list.indexOf(c1); int second = list.indexOf(c2); return second - first; } }; FocusTraversalPolicy policy = new SortingFocusTraversalPolicy(comp); frame.setFocusTraversalPolicy(policy); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("Shared Model"); JTextArea areaFiftyOne = new JTextArea(); JTextArea areaFiftyTwo = new JTextArea(); areaFiftyTwo.setDocument(areaFiftyOne.getDocument()); JTextArea areaFiftyThree = new JTextArea(); areaFiftyThree.setDocument(areaFiftyOne.getDocument()); frame.setLayout(new GridLayout(3, 1)); frame.add(new JScrollPane(areaFiftyOne)); frame.add(new JScrollPane(areaFiftyTwo)); frame.add(new JScrollPane(areaFiftyThree)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 300);// w ww . ja va 2 s . c o m frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel main = new JPanel(new GridLayout(2, 1)); JPanel scrollBarPanel = new JPanel(); final JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL, 0, 48, 0, 255); int height = scrollBar.getPreferredSize().height; scrollBar.setPreferredSize(new Dimension(175, height)); scrollBarPanel.add(scrollBar);/*w w w . j av a2 s . c o m*/ main.add(scrollBarPanel); JPanel sliderPanel = new JPanel(); final JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 255, 128); slider.setMajorTickSpacing(48); slider.setMinorTickSpacing(16); slider.setPaintTicks(true); sliderPanel.add(slider); main.add(sliderPanel); frame.add(main, BorderLayout.CENTER); scrollBar.addAdjustmentListener(new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { System.out.println("JScrollBar's current value = " + scrollBar.getValue()); } }); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { System.out.println("JSlider's current value = " + slider.getValue()); } }); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:JRadioButtonItemListener.java
public static void main(String args[]) { JFrame frame = new JFrame("Grouping Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); ButtonGroup group = new ButtonGroup(); JRadioButton aRadioButton = new JRadioButton("A"); JRadioButton bRadioButton = new JRadioButton("B"); ItemListener itemListener = new ItemListener() { String lastSelected;//from w w w . j av a 2 s . c o m public void itemStateChanged(ItemEvent itemEvent) { AbstractButton aButton = (AbstractButton) itemEvent.getSource(); int state = itemEvent.getStateChange(); String label = aButton.getText(); String msgStart; if (state == ItemEvent.SELECTED) { if (label.equals(lastSelected)) { msgStart = "Reselected -> "; } else { msgStart = "Selected -> "; } lastSelected = label; } else { msgStart = "Deselected -> "; } System.out.println(msgStart + label); } }; panel.add(aRadioButton); group.add(aRadioButton); panel.add(bRadioButton); group.add(bRadioButton); aRadioButton.addItemListener(itemListener); bRadioButton.addItemListener(itemListener); frame.add(panel); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Grouping Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); ButtonGroup group = new ButtonGroup(); JRadioButton aRadioButton = new JRadioButton("A"); JRadioButton bRadioButton = new JRadioButton("B"); ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changEvent) { AbstractButton aButton = (AbstractButton) changEvent.getSource(); ButtonModel aModel = aButton.getModel(); boolean armed = aModel.isArmed(); boolean pressed = aModel.isPressed(); boolean selected = aModel.isSelected(); System.out.println("Changed: " + armed + "/" + pressed + "/" + selected); }//from w w w .ja v a 2 s . c o m }; panel.add(aRadioButton); group.add(aRadioButton); panel.add(bRadioButton); group.add(bRadioButton); aRadioButton.addChangeListener(changeListener); bRadioButton.addChangeListener(changeListener); frame.add(panel); frame.setSize(300, 200); frame.setVisible(true); }
From source file:LabelTextPos.java
public static void main(String args[]) { JFrame frame = new JFrame("Label Text Pos"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = frame.getContentPane(); content.setLayout(new GridLayout(2, 2)); Border border = LineBorder.createGrayLineBorder(); Icon warnIcon = new ImageIcon("Warn.gif"); JLabel label1 = new JLabel(warnIcon); label1.setText("Left-Bottom"); label1.setHorizontalTextPosition(JLabel.LEFT); label1.setVerticalTextPosition(JLabel.BOTTOM); label1.setBorder(border);/*w w w . j ava2 s .c o m*/ content.add(label1); JLabel label2 = new JLabel(warnIcon); label2.setText("Right-TOP"); label2.setHorizontalTextPosition(JLabel.RIGHT); label2.setVerticalTextPosition(JLabel.TOP); label2.setBorder(border); content.add(label2); JLabel label3 = new JLabel(warnIcon); label3.setText("Center-Center"); label3.setHorizontalTextPosition(JLabel.CENTER); label3.setVerticalTextPosition(JLabel.CENTER); label3.setBorder(border); content.add(label3); JLabel label4 = new JLabel(warnIcon); label4.setText("Center-Bottom"); label4.setHorizontalTextPosition(JLabel.CENTER); label4.setVerticalTextPosition(JLabel.BOTTOM); label4.setBorder(border); content.add(label4); frame.setSize(300, 200); frame.setVisible(true); }