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

public static void main(String[] args) {

    JFrame frame = new JFrame("GradientsMiddle");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new GradientsMiddle());
    frame.setSize(350, 350);// w w  w . ja  va2s.c om
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:GridLayoutTest.java

public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("GridLayout Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new GridLayout(3, 2));
    frame.add(new JButton("Button 1"));
    frame.add(new JButton("Button 2"));
    frame.add(new JButton("Button 3"));
    frame.add(new JButton("Button 4"));
    frame.add(new JButton("Button 5"));
    frame.add(new JButton("Button 6"));
    frame.add(new JButton("Button 7"));
    frame.add(new JButton("Button 8"));
    frame.pack();/*from  ww w  . j av a2 s  . c  om*/
    frame.setVisible(true);
}

From source file:SplitPaneSample.java

public static void main(String args[]) {
    JFrame vFrame = new JFrame("JSplitPane Sample");
    vFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JSplitPane vSplitPane = new JSplitPane();
    vSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    vFrame.getContentPane().add(vSplitPane, BorderLayout.CENTER);
    vFrame.setSize(300, 150);/*w  ww . j  a  v a 2s  .co  m*/
    vFrame.setVisible(true);

    JFrame hFrame = new JFrame("JSplitPane Sample");
    JSplitPane hSplitPane = new JSplitPane();
    hFrame.getContentPane().add(hSplitPane, BorderLayout.CENTER);
    hFrame.setSize(300, 150);
    hFrame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("BorderLayout Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container container = frame.getContentPane();

    // Add a button to each of the five areas of the BorderLayout
    container.add(new JButton("North"), BorderLayout.NORTH);
    container.add(new JButton("South"), BorderLayout.SOUTH);
    container.add(new JButton("East"), BorderLayout.EAST);
    container.add(new JButton("West"), BorderLayout.WEST);
    container.add(new JButton("Center"), BorderLayout.CENTER);

    frame.pack();//w  w  w. jav  a2 s  . c o  m
    frame.setVisible(true);
}

From source file:JListSelectionModeAnchor.java

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

    JList jlist = new JList(new String[] { "A", "B", "C" });

    jlist.getSelectionModel().setAnchorSelectionIndex(0);
    jlist.getSelectionModel().setLeadSelectionIndex(2);

    JScrollPane scrollPane1 = new JScrollPane(jlist);
    frame.add(scrollPane1, BorderLayout.CENTER);

    frame.setSize(640, 300);/*  w ww .j a v a2s .co m*/
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    JFrame f = new JFrame("JTabbedPane Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTabbedPane tabbedPane = new JTabbedPane();
    addIt(tabbedPane, "Tab One");
    addIt(tabbedPane, "Tab Two");
    addIt(tabbedPane, "Tab Three");
    f.add(tabbedPane, BorderLayout.CENTER);
    f.setSize(300, 200);//w w w.j  a  va2 s  . c  om
    f.setVisible(true);
}

From source file:Textures.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Textures");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new Textures());
    frame.setSize(360, 120);// w ww .  j a  va 2 s  .c  o m
    frame.setVisible(true);
}

From source file:GridBag4.java

public static void main(String[] args) {
    JFrame frame = new JFrame("GridBag4");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(300, 100);//from w w w. ja  va  2  s.  c  om
    frame.setLocation(200, 200);
    frame.setContentPane(new GridBag4());
    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" };
    JTree tree = new JTree(array);
    tree.setEditable(true);//from  ww  w  . ja v a 2 s .co  m
    tree.setRootVisible(true);

    DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer();
    String elements[] = { "A", "B", "C", "D" };
    JComboBox comboBox = new JComboBox(elements);
    comboBox.setEditable(true);
    TreeCellEditor comboEditor = new DefaultCellEditor(comboBox);
    TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer, comboEditor);
    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) {
    JPanel panel = new JPanel();
    panel.setLayout(new OverlayLayout(panel));

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.add("1", new JTextField("one"));
    tabbedPane.add("2", new JTextField("two"));
    tabbedPane.setAlignmentX(1.0f);/* ww  w  .j  a v a2s .c  om*/
    tabbedPane.setAlignmentY(0.0f);

    JCheckBox checkBox = new JCheckBox("Add tab");
    checkBox.setOpaque(false);
    checkBox.setAlignmentX(1.0f);
    checkBox.setAlignmentY(0.0f);

    panel.add(checkBox);
    panel.add(tabbedPane);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(panel);
    frame.setSize(400, 100);
    frame.setVisible(true);
}