List of usage examples for javax.swing JFrame setDefaultCloseOperation
@BeanProperty(preferred = true, enumerationValues = { "WindowConstants.DO_NOTHING_ON_CLOSE", "WindowConstants.HIDE_ON_CLOSE", "WindowConstants.DISPOSE_ON_CLOSE", "WindowConstants.EXIT_ON_CLOSE" }, description = "The frame's default close operation.") public void setDefaultCloseOperation(int operation)
From source file:ActionButtonSample.java
public static void main(String args[]) { JFrame frame = new JFrame("DefaultButton"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { String command = actionEvent.getActionCommand(); System.out.println("Selected: " + command); }//from w w w. j ava 2 s .c o m }; frame.setLayout(new GridLayout(2, 2, 10, 10)); JButton button1 = new JButton("Text Button"); button1.setActionCommand("First"); button1.addActionListener(actionListener); frame.add(button1); frame.setSize(300, 200); frame.setVisible(true); }
From source file:BasicShapes.java
public static void main(String[] args) { JFrame frame = new JFrame("Basic Shapes"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new BasicShapes()); frame.setSize(350, 250);/*from w w w . j ava 2 s . c o m*/ frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:MnemonicSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Mnemonics"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = frame.getContentPane(); content.setLayout(new GridLayout(1, 0)); JButton button1 = new JButton("Warning"); button1.setMnemonic(KeyEvent.VK_W); content.add(button1);/* w w w. j a v a 2s . c om*/ JButton button2 = new JButton("Warning"); button2.setMnemonic(KeyEvent.VK_H); content.add(button2); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Double Title"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); TitledBorder topBorder = BorderFactory.createTitledBorder("Top"); topBorder.setTitlePosition(TitledBorder.TOP); TitledBorder doubleBorder = new TitledBorder(topBorder, "Bottom", TitledBorder.RIGHT, TitledBorder.BOTTOM); JButton doubleButton = new JButton(); doubleButton.setBorder(doubleBorder); Container contentPane = frame.getContentPane(); contentPane.add(doubleButton, BorderLayout.CENTER); frame.setSize(300, 100);/* w ww.j a va 2 s . c o m*/ frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame f = new JFrame("JPasswordField Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Box rowOne = Box.createHorizontalBox(); rowOne.add(new JLabel("Username")); rowOne.add(new JTextField()); Box rowTwo = Box.createHorizontalBox(); rowTwo.add(new JLabel("Password")); rowTwo.add(new JPasswordField()); f.add(rowOne, BorderLayout.NORTH); f.add(rowTwo, BorderLayout.SOUTH); f.setSize(300, 200);/*w ww . j a va2 s. c om*/ f.setVisible(true); }
From source file:GridBag2.java
public static void main(String[] args) { JFrame frame = new JFrame("GridBag2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(225, 150);/* w w w .j a v a2s . c o m*/ frame.setLocation(200, 200); frame.setContentPane(new GridBag2()); frame.setVisible(true); }
From source file:Points.java
public static void main(String[] args) { Points points = new Points(); JFrame frame = new JFrame("Points"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(points);// www . jav a 2 s. c om frame.setSize(250, 200); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel controlPane = new JPanel(); JPanel buttonPane = new JPanel(); controlPane.setLayout(new BoxLayout(controlPane, BoxLayout.PAGE_AXIS)); controlPane.setPreferredSize(new Dimension(200, 200)); controlPane.add(new JScrollPane(new JTextArea())); buttonPane.setLayout(new FlowLayout(FlowLayout.LEFT)); buttonPane.setPreferredSize(new Dimension(100, 40)); buttonPane.add(new JButton("Button1")); buttonPane.add(new JButton("Button2")); frame.add(controlPane, BorderLayout.NORTH); frame.add(buttonPane, BorderLayout.SOUTH); frame.pack();//w w w . j a v a 2s.c o m frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { int result = JOptionPane.showConfirmDialog(null, "Show over parent?"); for (int i = 1; i < 4; i++) { JFrame f = new JFrame("Frame " + i); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Component parent = (JOptionPane.OK_OPTION == result ? f : null); f.setSize(400, 300);/*from w w w.ja v a2s .c om*/ f.setLocationByPlatform(true); f.setVisible(true); JDialog d = new JDialog(f); d.setTitle("Dialog " + i); d.setSize(300, 200); d.setLocationRelativeTo(parent); d.setVisible(true); } }
From source file:VetoableChangeListenerDemo.java
public static void main(final String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JDesktopPane desktop = new JDesktopPane(); JInternalFrame palette = new JInternalFrame("Palette", true, true, true, true); palette.addVetoableChangeListener(new IconPolice()); palette.setBounds(350, 150, 100, 100); desktop.add(palette, JDesktopPane.PALETTE_LAYER); palette.setVisible(true);//from w w w . j a v a 2s . c om frame.add(desktop, BorderLayout.CENTER); frame.setSize(500, 300); frame.setVisible(true); }