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 frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

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

    frame.add(button, BorderLayout.CENTER);
    frame.setSize(350, 150);/*from ww  w .ja  va2 s . c  o m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new TestPane());
    frame.pack();/* w ww . j av  a2s . c  o  m*/
    frame.setVisible(true);
    System.out.println("Frame size = " + frame.getSize());
}

From source file:DialogBlockingExample.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(1);
    f.add(createPanel());//from   w  w w .  ja v  a  2 s. c o m
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLayeredPane desktop = new JDesktopPane();
    desktop.setOpaque(false);/*from www  .j  a  v  a 2s  . c o m*/
    desktop.add(new SelfInternalFrame("1"), JLayeredPane.POPUP_LAYER);
    f.add(desktop, BorderLayout.CENTER);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:StringRectPaintPanel.java

public static void main(String[] args) {

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setContentPane(new StringRectPaintPanel());
    frame.setSize(500, 300);/*  w w w  .  j a  v  a2 s. c o  m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(pb);/* www .j a  va  2  s  .  c  o  m*/
    f.pack();
    f.setVisible(true);

    Timer timer = new Timer(50, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            progress += 1;
            if (progress >= 100) {
                progress = 100;
                ((Timer) e.getSource()).stop();
            }
            pb.setValue(progress);
        }
    });
    timer.start();
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame("Fixed size content");
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    Container c = f.getContentPane();
    c.setBackground(Color.YELLOW);

    Dimension d = new Dimension(400, 40);
    c.setPreferredSize(d);//from w  w w . jav  a2 s . c  om
    f.pack();
    f.setResizable(false);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    Main mainPanel = new Main();
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(mainPanel);// w  ww  . ja  va 2 s.c  om
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JTextArea textArea = new JTextArea();

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    DefaultCaret caret = new DefaultCaret() {
        @Override/*  www.j a v a2  s  . co  m*/
        public boolean isSelectionVisible() {
            return true;
        }
    };
    textArea.setCaret(caret);
    textArea.setFont(new java.awt.Font("Miriam Fixed", 0, 13));

    Color color = Color.BLUE;
    // textArea.setBackground(color);
    textArea.setSelectedTextColor(color);
    f.getContentPane().add(new JScrollPane(textArea));
    f.pack();
    f.setVisible(true);
}

From source file:CaretEeventListener.java

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

    JTextField textField = new JTextField();

    textField.addCaretListener(new CaretListener() {

        public void caretUpdate(CaretEvent e) {
            System.out.println(e);

        }//w ww . j  a va  2s.  co m
    });

    frame.add(new JScrollPane(textField));

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