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:Main.java

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

    JComponent leftButton = new JButton("Left");
    JComponent rightButton = new JButton("Right");
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setLeftComponent(leftButton);
    splitPane.setRightComponent(rightButton);

    horizontalFrame.add(splitPane, BorderLayout.CENTER);
    horizontalFrame.setSize(150, 150);//from   w ww .  ja  v  a2s  . com
    horizontalFrame.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    MaskFormatter formatter = new MaskFormatter("###-##-####");
    JFormattedTextField tf = new JFormattedTextField(formatter);
    JPanel panel = new JPanel(new BorderLayout());
    panel.add(tf, BorderLayout.NORTH);
    JButton clickBtn = new JButton("Click me!");
    clickBtn.addActionListener(e -> {
        if (!tf.getText().matches(formatter.getMask())) {
            System.err.println("Your Input does not match the pattern!");
        } else {/*w w w.  j  a v a  2  s .co m*/
            System.out.println(tf.getText());
        }
    });
    panel.add(clickBtn, BorderLayout.SOUTH);
    JFrame f = new JFrame();

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(panel, BorderLayout.CENTER);
    f.setSize(800, 600);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Selecting CheckBox");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JCheckBox checkBox = new JCheckBox("Hi");

    checkBox.getModel().setMnemonic((char) 'H');

    frame.add(checkBox, BorderLayout.NORTH);
    frame.setSize(300, 100);/* w w  w  .  j a v  a 2  s.  c  o  m*/
    frame.setVisible(true);
}

From source file:TreeEdit.java

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

    Object array[] = { Boolean.TRUE, Boolean.FALSE, "Hello" }; // Hello will map to false
    JTree tree = new JTree(array);
    tree.setEditable(true);/*  w ww.j  av a 2  s. c  om*/
    tree.setRootVisible(true);

    JCheckBox checkBox = new JCheckBox();

    TreeCellEditor editor = new DefaultCellEditor(checkBox);
    tree.setCellEditor(editor);

    JScrollPane scrollPane = new JScrollPane(tree);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("JSeparator Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setLayout(new GridLayout(0, 1));
    JLabel above = new JLabel("Above Separator");
    f.add(above);//from w w  w.  j  a v a  2  s  .c  om
    JSeparator separator = new JSeparator();
    f.add(separator);
    JLabel below = new JLabel("Below Separator");
    f.add(below);
    f.setSize(300, 100);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Selecting CheckBox");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JCheckBox checkBox = new JCheckBox("Hi");

    checkBox.getModel().setSelected(true);

    frame.add(checkBox, BorderLayout.NORTH);
    frame.setSize(300, 100);//from  ww  w  .j  ava  2  s. co m
    frame.setVisible(true);
}

From source file:JListLocationToIndexSample.java

public static void main(String args[]) {
    String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H" };
    JFrame frame = new JFrame("Selecting JList");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JList jlist = new JList(labels);
    JScrollPane scrollPane1 = new JScrollPane(jlist);
    frame.add(scrollPane1, BorderLayout.CENTER);

    System.out.println(jlist.indexToLocation(5));
    frame.setSize(350, 200);/*from  ww w.j  a v a  2s .c  o  m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Selecting CheckBox");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JCheckBox checkBox = new JCheckBox("Hi");

    checkBox.getModel().setPressed(true);

    frame.add(checkBox, BorderLayout.NORTH);
    frame.setSize(300, 100);/*from  ww  w . j  a  v a 2  s  . c  o m*/
    frame.setVisible(true);
}

From source file:Main.java

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

    Action action = new ShowAction();
    JCheckBox button = new JCheckBox(action);

    frame.add(button, BorderLayout.CENTER);
    frame.setSize(350, 150);/*from  ww w .  j  a v  a2s .c om*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Layout");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    int horizontalGap = 20;
    int verticalGap = 10;
    Container contentPane = frame.getContentPane();
    FlowLayout flowLayout = new FlowLayout(FlowLayout.LEADING, horizontalGap, verticalGap);
    contentPane.setLayout(flowLayout);/*from  w w w  .j  av  a  2 s  .  c  o  m*/
    frame.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

    for (int i = 1; i <= 5; i++) {
        contentPane.add(new JButton("Button  " + i));
    }
    frame.pack();
    frame.setVisible(true);
}