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

public static void main(String args[]) {
    JFrame f = new JFrame("JToggleButton Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(new JToggleButton("North"), BorderLayout.NORTH);
    f.add(new JToggleButton("East"), BorderLayout.EAST);
    f.add(new JToggleButton("West"), BorderLayout.WEST);
    f.add(new JToggleButton("Center"), BorderLayout.CENTER);
    f.add(new JToggleButton("South"), BorderLayout.SOUTH);
    f.setSize(300, 200);//from w w w .  j a va  2 s.  c o  m
    f.setVisible(true);
}

From source file:Main.java

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

    JSlider oneJSlider = new JSlider();

    int newValue = 2;
    int newExtent = 10;
    int newMin = 0;
    int newMax = 10;
    oneJSlider.getModel().setRangeProperties(newValue, newExtent, newMin, newMax, true);
    int value = oneJSlider.getValue();
    System.out.println(value);/*from   ww w .  jav a2s .co m*/

    oneJSlider.setPaintTicks(true);

    frame.add(oneJSlider, BorderLayout.NORTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame jFrame = new JFrame();
    jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    jFrame.setSize(400, 300);//  w  w  w .j av a2 s  .  co  m
    JPanel panel = new JPanel(new FlowLayout());
    jFrame.setContentPane(panel);

    JEditorPane editor = new JEditorPane();
    new Main().remove_border(editor);
    panel.add(editor);

    jFrame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("Filled Slider");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JSlider js1 = new JSlider();
    js1.putClientProperty("JSlider.isFilled", Boolean.TRUE);
    JSlider js2 = new JSlider();
    js2.putClientProperty("JSlider.isFilled", Boolean.FALSE);
    frame.getContentPane().add(js1, BorderLayout.NORTH);
    frame.getContentPane().add(js2, BorderLayout.SOUTH);
    frame.setSize(300, 200);/*from  ww w .j  ava  2 s .  c o m*/
    frame.setVisible(true);
}

From source file:TitledExample.java

public static void main(String s[]) {
    JFrame frame = new JFrame("Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(200, 100);// w  ww.ja v a 2  s.c  om
    frame.setContentPane(new TitledExample());
    frame.setVisible(true);
}

From source file:Main.java

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

    JLabel label = new JLabel("Name: ");
    label.setDisplayedMnemonic(KeyEvent.VK_N);

    JTextField textField = new JTextField();
    label.setLabelFor(textField);//  www .  j a  v  a2s .  co m

    panel.add(label, BorderLayout.WEST);
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel, BorderLayout.NORTH);
    frame.add(new JButton("Somewhere Else"), BorderLayout.SOUTH);
    frame.setSize(250, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    String[] columnNames = { "Date", "Field", "Home Team", "Visitor Team", "Score" };
    JFrame guiFrame = new JFrame();
    guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    guiFrame.setSize(500, 500);//from w  ww .  java 2 s .c  o  m

    JPanel panel = new JPanel();
    panel.setSize(450, 450);
    JLabel titleLabel = new JLabel("OK");
    String[][] data = new String[0][0];
    JTable scheduleTable = new JTable(data, columnNames);
    JScrollPane scrollPane = new JScrollPane(scheduleTable);
    panel.add(scrollPane);
    panel.add(titleLabel);

    guiFrame.add(panel);
    guiFrame.setVisible(true);
}

From source file:GridBagLayoutColumnSpanHORIZONTAL.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();
    gbc.gridx = 1;//from   w ww. j  a  v a 2s .c  o  m
    gbc.gridy = GridBagConstraints.RELATIVE;
    pane.add(new JButton("First row, first column"), gbc);
    pane.add(new JButton("Second row"), gbc);
    gbc.gridwidth = 2;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    pane.add(new JButton("Third row, spans two columns"), gbc);
    gbc.gridwidth = 1;
    gbc.fill = GridBagConstraints.NONE;
    gbc.gridx = GridBagConstraints.RELATIVE;
    pane.add(new JButton("First row, second column"), gbc);
    f.setSize(400, 300);
    f.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] args) {
    JFrame frame = new JFrame("MoveButton");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(250, 200);//  w  ww.j av a2 s .com
    frame.setLocation(200, 200);
    frame.setContentPane(new MainClass());
    frame.setVisible(true);
}

From source file:Translation.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Translation");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new Translation());
    frame.setSize(300, 200);/*from   www .j av  a 2s  . co m*/
    frame.setVisible(true);
}