Tóm Tắt
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)
In this page you can find the example usage for javax.swing JFrame setDefaultCloseOperation.
Source Link
Document
Sets the operation that will happen by default when the user initiates a “close” on this frame.
Usage
Sets the operation that will happen by default when the user initiates a “close” on this frame.
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);/
*
f
r
o
m
w
w
w
.
j
a
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();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new
BorderLayout()); frame.add(new
TestPane()); frame.pack();/
*
w
w
w
.
j
a
v
a
2
s
.
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());/
/
f
r
o
m
w
w
w
.
j
a
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);/
*
f
r
o
m
w
w
w
.
j
a
v
a
2
s
.
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
a
2
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);/
*
w
w
w
.
j
a
v
a
2
s
.
c
o
m
*
/
f.pack(); f.setVisible(true); Timer timer =new
Timer(50,new
ActionListener() { @Overridepublic
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);/
/
f
r
o
m
w
w
w
.
j
a
v
a
2
s
.
c
o
m
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
w
w
.
j
a
v
a
2
s
.
c
o
m
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/
*
w
w
w
.
j
a
v
a
2
s
.
c
o
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
w
w
.
j
a
v
a
2
s
.
c
o
m
}); frame.add(new
JScrollPane(textField)); frame.setSize(300, 200); frame.setVisible(true); }