本文整理了Java中java.awt.Window.dispose()
方法的一些代码示例,展示了Window.dispose()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Window.dispose()
方法的具体详情如下:
包路径:java.awt.Window
类名称:Window
方法名:dispose
[英]Releases all of the native screen resources used by this Window
, its subcomponents, and all of its owned children. That is, the resources for these Component
s will be destroyed, any memory they consume will be returned to the OS, and they will be marked as undisplayable.
The Window
and its subcomponents can be made displayable again by rebuilding the native resources with a subsequent call to pack
or show
. The states of the recreated Window
and its subcomponents will be identical to the states of these objects at the point where the Window
was disposed (not accounting for additional modifications between those actions).
Note: When the last displayable window within the Java virtual machine (VM) is disposed of, the VM may terminate. See AWT Threading Issues for more information.
[中]释放此Window
及其子组件及其所有子组件使用的所有本机屏幕资源。也就是说,这些Component
的资源将被销毁,它们消耗的任何内存都将返回到操作系统,并且它们将被标记为不可扩展。Window
及其子组件可以通过调用pack
或show
重新构建本机资源来再次显示。重新创建的Window
及其子组件的状态将与处置Window
时这些对象的状态相同(不考虑这些操作之间的其他修改)。
注意:当Java虚拟机(VM)中的最后一个可显示窗口被释放时,VM可能会终止。有关更多信息,请参见{$0$}。
代码示例来源:origin: stackoverflow.com
import java.awt.event.*;
import javax.swing.*;
public class YourDialog extends JDialog implements ActionListener {
JButton button;
public YourDialog() {
button = new JButton("Close");
button.addActionListener(this);
add(button);
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
dispose();
}
}
代码示例来源:origin: stackoverflow.com
constraints.fill = GridBagConstraints.BOTH;
JLabel l = new JLabel("You have got 2 new Messages.");
panel.add(l, constraints);
constraints.gridx++;
constraints.weightx = 0f;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.NORTH;
JButton b = new JButton(new AbstractAction("x") {
dialog.dispose();
b.setMargin(new Insets(1, 4, 1, 4));
b.setFocusable(false);
panel.add(b, constraints);
dialog.setUndecorated(true);
dialog.setSize(300, 100);
代码示例来源:origin: stackoverflow.com
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class OptionTest {
public static void main ( String [] args ) {
JFrame frame = new JFrame("My dialog asks....");
frame.setUndecorated( true );
frame.setVisible( true );
frame.setLocationRelativeTo( null );
String message = JOptionPane.showInputDialog(frame,
"Would this be enough?.",
"My dialog asks....",
JOptionPane.INFORMATION_MESSAGE);
System.out.println( "Got " + message );
frame.dispose();
}
}
代码示例来源:origin: abbot/abbot
public void run() {
parent.setVisible(false);
parent.dispose();
}
});
代码示例来源:origin: stackoverflow.com
package test;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.JFrame;
public class TestFrame extends JFrame{
public TestFrame thisFrame;
public TestFrame(){
this.setSize(400, 400);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
public static void main(String[] args){
TestFrame test = new TestFrame();
test.addComponentListener(new ComponentAdapter() {
@Override
public void componentHidden(ComponentEvent e) {
System.out.println("Replace sysout with your method call");
((JFrame)(e.getComponent())).dispose();
}
});
}
}
代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop
public void propertyChange(PropertyChangeEvent evt) {
JXLoginPane.Status status = (JXLoginPane.Status)evt.getNewValue();
switch (status) {
case NOT_STARTED:
break;
case IN_PROGRESS:
cancelButton.setEnabled(false);
break;
case CANCELLED:
cancelButton.setEnabled(true);
w.pack();
break;
case FAILED:
cancelButton.setEnabled(true);
panel.passwordField.requestFocusInWindow();
w.pack();
break;
case SUCCEEDED:
w.setVisible(false);
w.dispose();
}
for (PropertyChangeListener l : w.getPropertyChangeListeners("status")) {
PropertyChangeEvent pce = new PropertyChangeEvent(w, "status", evt.getOldValue(), evt.getNewValue());
l.propertyChange(pce);
}
}
});
代码示例来源:origin: stackoverflow.com
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
btn = new JButton("Open the other JFrame!");
btn.addActionListener(this);
btn.setActionCommand("Open");
add(btn);
pack();
dispose();
new AnotherJFrame();
public void run()
new StartupWindow().setVisible(true);
代码示例来源:origin: stackoverflow.com
l.setOpaque(false);
c.add(l, constraints);
constraints.anchor = GridBagConstraints.NORTH;
final JButton b = new JButton(new AbstractAction("x") {
f.dispose();
b.setFocusable(false);
c.add(b, constraints);
代码示例来源:origin: stackoverflow.com
import javax.swing.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class Test {
public Test() {
final JFrame frame = new JFrame("Screen Saver");
frame.validate();
frame.setVisible(true);
KeyAdapter listener = new KeyAdapter() {
@Override public void keyPressed(KeyEvent e) {
frame.dispose();
}
};
frame.addKeyListener(listener);
}
public static void main(String[] args) {
new Test();
}
}
代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop
public void actionPerformed(ActionEvent e) {
//change panel status to canceled!
panel.status = JXLoginPane.Status.CANCELLED;
w.setVisible(false);
w.dispose();
}
});
代码示例来源:origin: org.swinglabs.swingx/swingx-core
@Override
public void propertyChange(PropertyChangeEvent evt) {
JXLoginPane.Status status = (JXLoginPane.Status)evt.getNewValue();
switch (status) {
case NOT_STARTED:
break;
case IN_PROGRESS:
cancelButton.setEnabled(false);
break;
case CANCELLED:
cancelButton.setEnabled(true);
w.pack();
break;
case FAILED:
cancelButton.setEnabled(true);
panel.passwordField.requestFocusInWindow();
w.pack();
break;
case SUCCEEDED:
w.setVisible(false);
w.dispose();
}
for (PropertyChangeListener l : w.getPropertyChangeListeners("status")) {
PropertyChangeEvent pce = new PropertyChangeEvent(w, "status", evt.getOldValue(), evt.getNewValue());
l.propertyChange(pce);
}
}
});
代码示例来源:origin: stackoverflow.com
JButton showWaitBtn = new JButton(new ShowWaitAction("Show Wait Dialog"));
JPanel panel = new JPanel();
panel.add(showWaitBtn);
JFrame frame = new JFrame("Frame");
frame.getContentPane().add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
if (evt.getPropertyName().equals("state")) {
if (evt.getNewValue() == SwingWorker.StateValue.DONE) {
dialog.dispose();
progressBar.setIndeterminate(true);
JPanel panel = new JPanel(new BorderLayout());
panel.add(progressBar, BorderLayout.CENTER);
panel.add(new JLabel("Please wait......."), BorderLayout.PAGE_START);
dialog.add(panel);
dialog.pack();
dialog.setLocationRelativeTo(win);
dialog.setVisible(true);
代码示例来源:origin: org.swinglabs.swingx/swingx-core
/**
* @inheritDoc
*/
@Override
public void actionPerformed(ActionEvent e) {
w.setVisible(false);
w.dispose();
}
}
代码示例来源:origin: org.swinglabs.swingx/swingx-all
@Override
public void propertyChange(PropertyChangeEvent evt) {
JXLoginPane.Status status = (JXLoginPane.Status)evt.getNewValue();
switch (status) {
case NOT_STARTED:
break;
case IN_PROGRESS:
cancelButton.setEnabled(false);
break;
case CANCELLED:
cancelButton.setEnabled(true);
w.pack();
break;
case FAILED:
cancelButton.setEnabled(true);
panel.passwordField.requestFocusInWindow();
w.pack();
break;
case SUCCEEDED:
w.setVisible(false);
w.dispose();
}
for (PropertyChangeListener l : w.getPropertyChangeListeners("status")) {
PropertyChangeEvent pce = new PropertyChangeEvent(w, "status", evt.getOldValue(), evt.getNewValue());
l.propertyChange(pce);
}
}
});
代码示例来源:origin: stackoverflow.com
JFrame frame = new JFrame("WindowCommunication");
frame.getContentPane().add(new MyFramePanel());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
private JButton openDialogeBtn = new JButton("Open Dialog");
field.setFocusable(false);
add(field);
add(openDialogeBtn);
ModalityType.APPLICATION_MODAL);
dialog.getContentPane().add(dialogPanel);
dialog.pack();
dialog.setLocationRelativeTo(null);
private JButton okButton = new JButton("OK");
win.dispose();
代码示例来源:origin: org.swinglabs.swingx/swingx-core
@Override
public void actionPerformed(ActionEvent e) {
//change panel status to canceled!
panel.status = JXLoginPane.Status.CANCELLED;
w.setVisible(false);
w.dispose();
}
});
代码示例来源:origin: org.bidib.jbidib.swinglabs.swingx/swingx-core
@Override
public void propertyChange(PropertyChangeEvent evt) {
JXLoginPane.Status status = (JXLoginPane.Status)evt.getNewValue();
switch (status) {
case NOT_STARTED:
break;
case IN_PROGRESS:
cancelButton.setEnabled(false);
break;
case CANCELLED:
cancelButton.setEnabled(true);
w.pack();
break;
case FAILED:
cancelButton.setEnabled(true);
panel.passwordField.requestFocusInWindow();
w.pack();
break;
case SUCCEEDED:
w.setVisible(false);
w.dispose();
}
for (PropertyChangeListener l : w.getPropertyChangeListeners("status")) {
PropertyChangeEvent pce = new PropertyChangeEvent(w, "status", evt.getOldValue(), evt.getNewValue());
l.propertyChange(pce);
}
}
});
代码示例来源:origin: stackoverflow.com
jTextField1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBounds(new java.awt.Rectangle(0, 0, 0, 0));
java.awt.GridBagLayout layout = new java.awt.GridBagLayout();
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 3;
getContentPane().add(jLabel1, gridBagConstraints);
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
getContentPane().add(jTextField1, gridBagConstraints);
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
getContentPane().add(jLabel2, gridBagConstraints);
getContentPane().add(jButton1, gridBagConstraints);
pack();
dispose();
代码示例来源:origin: org.swinglabs.swingx/swingx-all
@Override
public void actionPerformed(ActionEvent e) {
//change panel status to canceled!
panel.status = JXLoginPane.Status.CANCELLED;
w.setVisible(false);
w.dispose();
}
});
代码示例来源:origin: stackoverflow.com
emailDialog.setLayout(new BorderLayout());
JButton sendMailBtn = new JButton("Send Email");
sendMailBtn.addActionListener(new ActionListener() {
emailDialog.dispose();
emailProgressDialog.add(new JLabel("Mail in progress"));
emailProgressDialog.pack();
emailProgressDialog.setVisible(true);
emailDialog.add(sendMailBtn, BorderLayout.SOUTH);
emailDialog.pack();
JButton openDialog = new JButton("Open emailDialog");
openDialog.addActionListener(new ActionListener() {
frame.getContentPane().add(openDialog);
protected void done() {
super.done();
dialog.dispose();
JOptionPane.showMessageDialog(dialog.getOwner(), "Message sent", "Success", JOptionPane.INFORMATION_MESSAGE);
内容来源于网络,如有侵权,请联系作者删除!