List of usage examples for java.awt Container add
public Component add(Component comp)
From source file:Main.java
public static void main(String[] args) { JFrame aWindow = new JFrame(); aWindow.setBounds(200, 200, 200, 200); aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = aWindow.getContentPane(); content.setLayout(new FlowLayout(FlowLayout.LEFT)); content.add(new JButton("www.java2s.com")); content.add(new JLabel("www.java2s.com")); content.add(new JTextField("www.java2s.com")); aWindow.setVisible(true);/*www. jav a2s. co m*/ }
From source file:TestOval.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label1 = new JLabel(new OvalIcon(20, 50)); JLabel label2 = new JLabel(new OvalIcon(50, 20)); JLabel label3 = new JLabel("Round!", new OvalIcon(60, 60), SwingConstants.CENTER); label3.setHorizontalTextPosition(SwingConstants.CENTER); Container c = f.getContentPane(); c.setLayout(new FlowLayout()); c.add(label1); c.add(label2);/*from w w w. ja v a 2s. c om*/ c.add(label3); f.pack(); f.setVisible(true); }
From source file:JToggleButtonEvents.java
public static void main(String[] args) { JToggleButton jtb = new JToggleButton("Press Me"); jtb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { System.out.println("ActionEvent!"); }/* w w w . j a va 2 s. c om*/ }); jtb.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ev) { System.out.println("ItemEvent!"); } }); jtb.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent ev) { System.out.println("ChangeEvent!"); } }); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = f.getContentPane(); c.setLayout(new FlowLayout()); c.add(jtb); f.pack(); f.setVisible(true); }
From source file:EventQueuePanel.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setTitle("EventQueueTest"); frame.setSize(300, 200);// w ww.j ava2 s. c om frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); Container contentPane = frame.getContentPane(); contentPane.add(new EventQueuePanel()); frame.show(); }
From source file:ASoftBevelBorder.java
public static void main(String args[]) { JFrame frame = new JFrame("Soft Bevel Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border raisedBorder = new SoftBevelBorder(SoftBevelBorder.RAISED); Border loweredBorder = new SoftBevelBorder(SoftBevelBorder.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)); contentPane.add(raisedButton); contentPane.add(loweredButton);//from ww w . j a v a 2s . c o m frame.setSize(300, 100); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame("Soft Bevel Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border raisedBorder = new SoftBevelBorder(SoftBevelBorder.RAISED); Border loweredBorder = new SoftBevelBorder(SoftBevelBorder.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)); contentPane.add(raisedButton); contentPane.add(loweredButton);/* w w w . j a v a 2 s.c o m*/ frame.setSize(300, 100); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { String[] items = new String[] { "", "Apple", "Banana", "Carrot" }; Color bgColor = UIManager.getColor("TextField.background"); UIManager.put("ComboBox.selectionBackground", new ColorUIResource(bgColor)); JComboBox<String> combo1 = new JComboBox<>(items); combo1.setPrototypeDisplayValue("XXXXXXXXXXXXXXX"); combo1.setEditable(true);/*from w ww.j a v a 2s .co m*/ combo1.setSelectedIndex(-1); JComboBox<String> combo2 = new JComboBox<>(items); combo2.setPrototypeDisplayValue("XXXXXXXXXXXXXXX"); combo2.setEditable(false); combo2.setSelectedIndex(-1); combo2.setBackground(bgColor); JFrame frame = new JFrame(); Container c = frame.getContentPane(); c.setLayout(new FlowLayout()); c.add(combo1); c.add(combo2); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 100); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = f.getContentPane(); c.add(new Justify()); f.pack();/*from w w w .j a va 2 s . com*/ f.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); contentPane.add(loweredButton);/* ww w . j a va 2 s . c o m*/ frame.setSize(300, 100); frame.setVisible(true); }
From source file:ASoftBevelBorder.java
public static void main(String args[]) { JFrame frame = new JFrame("Soft Bevel Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border raisedBorder = new SoftBevelBorder(SoftBevelBorder.RAISED); Border loweredBorder = new SoftBevelBorder(SoftBevelBorder.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)); contentPane.add(raisedButton); contentPane.add(loweredButton);/*from w w w . j av a 2 s.c o m*/ frame.setSize(300, 100); frame.setVisible(true); }