List of usage examples for java.awt Container add
public void add(Component comp, Object constraints)
From source file:YAxisAlignXButtonMixed.java
public static void main(String args[]) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container panel = makeIt("AWT Button"); Container contentPane = frame.getContentPane(); contentPane.add(panel, BorderLayout.CENTER); frame.setSize(300, 200);/*w ww .jav a2 s. com*/ frame.setVisible(true); }
From source file:TextSlider.java
public static void main(String args[]) { JFrame f = new JFrame("Text Slider"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final TextSlider ts = new TextSlider(); ts.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Text: " + ts.getText()); }//w ww. jav a2s .c om }); Container c = f.getContentPane(); c.add(ts, BorderLayout.NORTH); f.setSize(300, 200); f.setVisible(true); }
From source file:AButtonGroup.java
public static void main(String args[]) { JFrame frame = new JFrame("Button Group"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Examples"); panel.setBorder(border);/*from w w w .j a va2 s .com*/ ButtonGroup group = new ButtonGroup(); AbstractButton abstract1 = new JToggleButton("Toggle Button"); panel.add(abstract1); group.add(abstract1); AbstractButton abstract2 = new JRadioButton("Radio Button"); panel.add(abstract2); group.add(abstract2); AbstractButton abstract3 = new JCheckBox("Check Box"); panel.add(abstract3); group.add(abstract3); AbstractButton abstract4 = new JRadioButtonMenuItem("Radio Button Menu Item"); panel.add(abstract4); group.add(abstract4); AbstractButton abstract5 = new JCheckBoxMenuItem("Check Box Menu Item"); panel.add(abstract5); group.add(abstract5); Container contentPane = frame.getContentPane(); contentPane.add(panel, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Verifier Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textField1 = new JTextField(); JTextField textField2 = new JTextField(); JTextField textField3 = new JTextField(); InputVerifier verifier = new InputVerifier() { public boolean verify(JComponent comp) { boolean returnValue; JTextField textField = (JTextField) comp; try { Integer.parseInt(textField.getText()); returnValue = true;/*from www . j a va 2s.com*/ } catch (NumberFormatException e) { returnValue = false; } return returnValue; } }; textField1.setInputVerifier(verifier); textField3.setInputVerifier(verifier); Container contentPane = frame.getContentPane(); contentPane.add(textField1, BorderLayout.NORTH); contentPane.add(textField2, BorderLayout.CENTER); contentPane.add(textField3, BorderLayout.SOUTH); frame.setSize(300, 100); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Examples"); panel.setBorder(border);// w w w . j a va 2 s .c om ButtonGroup group = new ButtonGroup(); AbstractButton abstract1 = new JToggleButton("Toggle Button"); panel.add(abstract1); group.add(abstract1); AbstractButton abstract2 = new JRadioButton("Radio Button"); panel.add(abstract2); group.add(abstract2); AbstractButton abstract3 = new JCheckBox("Check Box"); panel.add(abstract3); group.add(abstract3); AbstractButton abstract4 = new JRadioButtonMenuItem("Radio Button Menu Item"); panel.add(abstract4); group.add(abstract4); AbstractButton abstract5 = new JCheckBoxMenuItem("Check Box Menu Item"); panel.add(abstract5); group.add(abstract5); JFrame frame = new JFrame("Button Group"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.add(panel, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:ActiveSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Active Example"); UIManager.put(LABEL_FACTORY, new ActiveLabel()); final JPanel panel = new JPanel(); JButton button = new JButton("Get"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JLabel label = (JLabel) UIManager.get(LABEL_FACTORY); panel.add(label);/*from ww w. j av a 2 s . c o m*/ panel.revalidate(); } }; button.addActionListener(actionListener); Container contentPane = frame.getContentPane(); contentPane.add(panel, BorderLayout.CENTER); contentPane.add(button, BorderLayout.SOUTH); frame.setSize(200, 200); frame.setVisible(true); }
From source file:SelectingButton.java
public static void main(String args[]) { JFrame frame = new JFrame("Selecting Button"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton theButton = new JButton("Button"); ActionListener aListener = new ActionListener() { public void actionPerformed(ActionEvent event) { AbstractButton aButton = (AbstractButton) event.getSource(); boolean selected = aButton.getModel().isSelected(); System.out.println("Action - selected=" + selected + "\n"); }// w w w .j a v a2 s .co m }; ChangeListener cListener = new ChangeListener() { public void stateChanged(ChangeEvent event) { AbstractButton aButton = (AbstractButton) event.getSource(); ButtonModel aModel = aButton.getModel(); boolean armed = aModel.isArmed(); boolean pressed = aModel.isPressed(); boolean selected = aModel.isSelected(); System.out.println("Changed: " + armed + "/" + pressed + "/" + selected); } }; theButton.addActionListener(aListener); theButton.addChangeListener(cListener); Container contentPane = frame.getContentPane(); contentPane.add(theButton, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:ScreenDump.java
public static void main(String args[]) { JFrame frame = new JFrame("Action Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final Action printAction = new PrintHelloAction(); JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("File"); menuBar.add(menu);//from ww w .ja v a 2 s . com JMenuItem menuItem = new JMenuItem("Print"); KeyStroke ctrlP = KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_MASK); menuItem.setAccelerator(ctrlP); menuItem.addActionListener(printAction); menu.add(menuItem); JButton fileButton = new JButton("About"); fileButton.setMnemonic(KeyEvent.VK_A); fileButton.addActionListener(printAction); frame.setJMenuBar(menuBar); Container contentPane = frame.getContentPane(); contentPane.add(fileButton, BorderLayout.SOUTH); frame.setSize(300, 100); frame.setVisible(true); }
From source file:TabbedPaneTest.java
public static void main(String args[]) { JFrame frame = new JFrame("JTabbedPane"); final Container contentPane = frame.getContentPane(); JTabbedPane jtp = new JTabbedPane(); contentPane.add(jtp, BorderLayout.CENTER); for (int i = 0; i < 5; i++) { JButton button = new JButton("Card " + i); jtp.add("Btn " + i, button); }/* w w w .j ava2s . c om*/ frame.setSize(300, 200); frame.show(); }
From source file:XAxisDiffAlign.java
public static void main(String args[]) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container panel1 = makeIt("Mixed", false); Container panel2 = makeIt("Mixed", true); Container contentPane = frame.getContentPane(); contentPane.add(panel1, BorderLayout.WEST); contentPane.add(panel2, BorderLayout.EAST); frame.pack();/*from w ww . j av a2s.c o m*/ frame.setVisible(true); }