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:AnEmptyBorder.java
public static void main(String args[]) { JFrame frame = new JFrame("Empty Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border emptyBorder = BorderFactory.createEmptyBorder(20, 20, 0, 0); JButton emptyButton = new JButton("With Empty"); emptyButton.setBorder(emptyBorder);//from w w w. j ava 2 s. c o m JButton nonemptyButton = new JButton("Without Empty"); Container contentPane = frame.getContentPane(); contentPane.add(emptyButton, BorderLayout.NORTH); contentPane.add(nonemptyButton, BorderLayout.SOUTH); frame.setSize(300, 100); 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);/*from ww w . j a v a2 s .c om*/ 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:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("MoveButton"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(250, 200);/*w w w . ja v a 2 s. co m*/ frame.setLocation(200, 200); frame.setContentPane(new Main()); frame.setVisible(true); }
From source file:UsingFocusListener.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textField = new JTextField("A TextField"); KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); focusManager.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); System.out.println(prop); }//from w ww . j a va2s. co m }); frame.add(textField, "North"); frame.add(new JTextField(), "South"); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { JButton jb = new JButton("Press Me"); jb.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ev) { System.out.println("ItemEvent!"); }//from www. j a v a 2 s . c o m }); jb.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent ev) { System.out.println("ChangeEvent!"); } }); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { DefaultMutableTreeNode root = new DefaultMutableTreeNode("root"); DefaultTreeModel model = new DefaultTreeModel(root); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(new JTree(model))); f.getContentPane().add(new JButton(new AbstractAction("Add thousand children") { @Override/*from w ww . ja va 2 s .co m*/ public void actionPerformed(ActionEvent e) { int offset = root.getChildCount() + 1; for (int i = 0; i < 1000; i++) { DefaultMutableTreeNode child = new DefaultMutableTreeNode("Person " + (i + offset)); // model.insertNodeInto(child, root, root.getChildCount()); root.add(child); } model.nodeStructureChanged(root); } }), BorderLayout.PAGE_END); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame("Sizing Samples"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList jlist1 = new JList(labels); jlist1.setVisibleRowCount(4);/* ww w . j ava 2 s. com*/ JScrollPane scrollPane1 = new JScrollPane(jlist1); frame.add(scrollPane1, BorderLayout.NORTH); frame.setSize(300, 350); frame.setVisible(true); }
From source file:EtchedBorderSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Sample Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border etchedBorder = new EtchedBorder(EtchedBorder.RAISED, Color.RED, Color.PINK); JLabel aLabel = new JLabel("Bevel"); aLabel.setBorder(etchedBorder);/* w w w.j a va 2 s . com*/ aLabel.setHorizontalAlignment(JLabel.CENTER); frame.add(aLabel); frame.setSize(400, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame("Selection Modes"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList list1 = new JList(labels); JScrollPane sp1 = new JScrollPane(list1); sp1.setColumnHeaderView(new JLabel("List")); frame.add(sp1, BorderLayout.CENTER); frame.setSize(300, 200);/*from ww w .j ava2s . c o m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(200, 300);/* w w w .j a v a2 s . c om*/ PaintSurface canvas = new PaintSurface(); ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(3); executor.scheduleAtFixedRate(canvas, 0L, 100L, TimeUnit.MILLISECONDS); f.add(canvas); f.setVisible(true); }