List of usage examples for javax.swing JFrame getContentPane
public Container getContentPane()
contentPane
object for this frame. From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("JFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); // Add a close button JButton closeButton = new JButton("Close"); contentPane.add(closeButton);//from w ww.j av a2s. c o m closeButton.addActionListener(e -> { System.out.println(e.getActionCommand()); System.exit(0); }); frame.pack(); frame.setVisible(true); }
From source file:MyCanvas.java
public static void main(String[] a) { JFrame window = new JFrame(); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setBounds(30, 30, 300, 300);//from w ww . ja v a2 s. c om window.getContentPane().add(new MyCanvas()); window.setVisible(true); }
From source file:CloseAction.java
public static void main(String[] args) { JFrame frame = new JFrame("JFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JButton closeButton = new JButton(new CloseAction()); contentPane.add(closeButton);/*from w ww .j av a2 s. com*/ frame.pack(); frame.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!"); }//from w w w. j av a 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:AreaSubtracting.java
public static void main(String arg[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add("Center", new AreaSubtracting()); frame.pack();/*from ww w. jav a 2 s . c o m*/ frame.setSize(new Dimension(400, 300)); frame.setVisible(true); }
From source file:ComboBoxSample.java
public static void main(String args[]) { String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; String title = (args.length == 0 ? "Example JComboBox" : args[0]); JFrame frame = new JFrame(title); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentpane = frame.getContentPane(); JComboBox comboBox1 = new JComboBox(labels); comboBox1.setMaximumRowCount(5);/* w w w . j a v a2s . co m*/ contentpane.add(comboBox1, BorderLayout.NORTH); JComboBox comboBox2 = new JComboBox(labels); comboBox2.setEditable(true); contentpane.add(comboBox2, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:AreaExclusiveOr.java
public static void main(String arg[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add("Center", new AreaExclusiveOr()); frame.pack();//from w w w .j a v a2 s .c o m frame.setSize(new Dimension(400, 300)); frame.setVisible(true); }
From source file:AreaIntersecting.java
public static void main(String arg[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add("Center", new AreaIntersecting()); frame.pack();//from w ww.j a v a 2 s. c o m frame.setSize(new Dimension(400, 300)); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame("JToolbar Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = f.getContentPane(); JToolBar toolbar = new JToolBar(); Icon icon = MetalIconFactory.getFileChooserDetailViewIcon(); JToggleButton button = new JToggleButton(icon); toolbar.add(button);//from ww w .j av a 2 s . c o m icon = MetalIconFactory.getFileChooserHomeFolderIcon(); button = new JToggleButton(icon); toolbar.add(button); icon = MetalIconFactory.getFileChooserListViewIcon(); button = new JToggleButton(icon); toolbar.add(button); content.add(toolbar, BorderLayout.NORTH); f.setSize(300, 100); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { Main swapper = new Main(); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(swapper.getMainPanel()); frame.setJMenuBar(swapper.getMenuBar()); frame.pack();/*ww w .j av a2 s. c o m*/ frame.setLocationByPlatform(true); frame.setVisible(true); }