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

public static void main(String[] a) {

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

    JButton bn = new JButton();

    RepaintManager repaintManager = RepaintManager.currentManager(bn);
    repaintManager.setDoubleBufferingEnabled(false);

    bn.setDebugGraphicsOptions(/*from w  ww  . ja  v a  2s .co  m*/
            DebugGraphics.BUFFERED_OPTION | DebugGraphics.FLASH_OPTION | DebugGraphics.LOG_OPTION);

    frame.add(bn);

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

    frame.add(bn);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("Icon Slider");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Icon icon = new ImageIcon("logo.gif");
    UIDefaults defaults = UIManager.getDefaults();
    defaults.put("Slider.horizontalThumbIcon", icon);
    JSlider aJSlider = new JSlider();
    aJSlider.setPaintTicks(true);/*  w w w .ja  v a 2s  .c  o  m*/
    frame.add(aJSlider, BorderLayout.NORTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JButton("Press Me");

    jb.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ev) {
            System.out.println("ItemEvent!");
        }//w  w  w. j a v a2 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:JSplitPaneVerticalSetTopBottom.java

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

    JComponent topButton = new JButton("Left");
    JComponent bottomButton = new JButton("Right");
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setTopComponent(topButton);
    splitPane.setBottomComponent(bottomButton);

    horizontalFrame.add(splitPane, BorderLayout.CENTER);
    horizontalFrame.setSize(150, 150);//from   w ww  . j  a v a2 s .c om
    horizontalFrame.setVisible(true);

}

From source file:AddingInternalFramestoaJDesktopPane.java

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

    JDesktopPane desktop = new JDesktopPane();
    JInternalFrame internalFrame = new JInternalFrame("Can Do All", true, true, true, true);

    desktop.add(internalFrame);/*from  ww w.  j  av a 2  s .c  om*/

    internalFrame.setBounds(25, 25, 200, 100);

    JLabel label = new JLabel(internalFrame.getTitle(), JLabel.CENTER);
    internalFrame.add(label, BorderLayout.CENTER);

    internalFrame.setVisible(true);

    frame.add(desktop, BorderLayout.CENTER);
    frame.setSize(500, 300);
    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().setRollover(true);

    frame.add(checkBox, BorderLayout.NORTH);
    frame.setSize(300, 100);//from   w ww .  java 2 s. com
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {

    JEditorPane jep = new JEditorPane();
    jep.setEditable(false);//from  w  w  w  .  java 2  s  . c  o m

    try {
        jep.setPage("http://www.google.com");
    } catch (IOException e) {
        jep.setContentType("text/html");
        jep.setText("<html>Could not load http://www.google.com </html>");
    }

    JScrollPane scrollPane = new JScrollPane(jep);
    JFrame f = new JFrame();

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(scrollPane);
    f.setSize(512, 342);
    f.show();

}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Stepping Progress");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JProgressBar aJProgressBar = new JProgressBar(JProgressBar.VERTICAL);
    aJProgressBar.setStringPainted(true);
    aJProgressBar.setIndeterminate(true);

    frame.add(aJProgressBar, BorderLayout.NORTH);
    frame.setSize(300, 200);/*from  w  w  w .  ja  v a  2 s  .c o m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Sample Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border emptyBorder = new EmptyBorder(5, 10, 5, 10);

    JLabel aLabel = new JLabel("Bevel");
    aLabel.setBorder(emptyBorder);/*from   www  . j ava  2 s  .c  o m*/
    aLabel.setHorizontalAlignment(JLabel.CENTER);

    frame.add(aLabel);
    frame.setSize(400, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("JEditorPane Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = f.getContentPane();
    JEditorPane editor = new JEditorPane("text/html",
            "<H3>Help</H3><center><IMG src=file:///c:/a.jpg></center><li>One<li><i>Two</i><li><u>Three</u>");
    editor.setEditable(false);/*from  w  ww .j  a  v  a2  s.c om*/
    JScrollPane scrollPane = new JScrollPane(editor);
    content.add(scrollPane, BorderLayout.CENTER);
    f.setSize(300, 200);
    f.setVisible(true);
}