Example usage for javax.swing JFrame setDefaultCloseOperation

List of usage examples for javax.swing JFrame setDefaultCloseOperation

Introduction

In this page you can find the example usage for javax.swing JFrame setDefaultCloseOperation.

Prototype

@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) 

Source Link

Document

Sets the operation that will happen by default when the user initiates a "close" on this frame.

Usage

From source file:GridBagLayoutGridHeight.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container pane = f.getContentPane();
    pane.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    pane.add(new JLabel("First row, first column"), gbc);
    pane.add(new JLabel("First row, second column"), gbc);
    gbc.gridheight = GridBagConstraints.REMAINDER;
    gbc.fill = GridBagConstraints.VERTICAL;
    pane.add(new JLabel("First row, third column"), gbc);
    gbc.gridx = 0;//from w ww.j  av  a2  s.  c  o  m
    gbc.gridheight = 1;
    gbc.fill = GridBagConstraints.NONE;
    pane.add(new JButton("Second row"), gbc);
    pane.add(new JButton("Third row"), gbc);
    f.setSize(600, 300);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JTextField tf = new JTextField("mm");
    tf.setPreferredSize(tf.getPreferredSize());
    tf.setText("");

    JPanel pHacked = new JPanel();
    pHacked.add(tf);//w ww  .  ja  va 2s .com

    JPanel pStock = new JPanel();
    pStock.add(new JTextField(2));

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new java.awt.GridLayout(0, 1));
    frame.add(pHacked);
    frame.add(pStock);
    frame.setSize(150, 150);
    frame.setVisible(true);
    tf.requestFocus();
}

From source file:ABevelBorderLoweredBevelBorder.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Bevel Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border loweredBorder = BorderFactory.createLoweredBevelBorder();

    JButton button = new JButton("Raised");
    button.setBorder(loweredBorder);/*  w  ww .  ja v  a 2 s .co m*/
    frame.add(button);

    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:MultiClickThreshholdDemo.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    AbstractButton bn = new JButton();
    bn.setMultiClickThreshhold(1000);/*from   w  w  w .  j  a  va2 s  .  c om*/

    bn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("action");
        }
    });

    frame.add(bn);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    JFrame f = new JFrame("JEditorPane Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JEditorPane editor = new JEditorPane("text/html",
            "<H3>Help</H3><center>www.java2s.com</center><li>One<li><i>Two</i><li><u>Three</u>");
    editor.setEditable(false);/*from  w  w w .j a  v  a  2s  .c o m*/
    JScrollPane scrollPane = new JScrollPane(editor);
    f.add(scrollPane, BorderLayout.CENTER);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame("Test");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(createLogin(), BorderLayout.CENTER);
    JLabel admonition = new JLabel("CopyRight java2s.com.", JLabel.CENTER);
    f.add(admonition, BorderLayout.SOUTH);
    f.pack();/*from  ww w  .j a  va2  s.co  m*/
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Main");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.add(new Main());
    frame.setSize(200, 300);//from  ww  w.  j  a v  a2 s .co  m
    frame.setLocationByPlatform(true);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JToggleButton toggleButton = new JToggleButton("Toggle Button");
    // Define ActionListener
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            AbstractButton abstractButton = (AbstractButton) actionEvent.getSource();
            boolean selected = abstractButton.getModel().isSelected();
            System.out.println("Action - selected=" + selected + "\n");
        }//from w  w  w.ja  v  a  2 s  .co m
    };
    // Attach Listeners
    toggleButton.addActionListener(actionListener);
    frame.add(toggleButton, BorderLayout.NORTH);
    frame.setSize(300, 125);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel p = new Main();

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(p);/*  www.j a  v a  2  s .  c o m*/
    frame.setSize(300, 300);

    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    JFrame f = new JFrame("JSlider Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JSlider slider = new JSlider();
    slider.setMinorTickSpacing(5);//from w ww  .j a  v  a2  s  .c o  m
    slider.setMajorTickSpacing(10);
    slider.setPaintTicks(true);
    slider.setSnapToTicks(true);
    slider.setPaintTrack(false);
    slider.setPaintLabels(true);
    f.add(slider, BorderLayout.CENTER);
    f.setSize(300, 100);
    f.setVisible(true);
}