我有一個JDialog,並希望該商店後關閉它確認文本框的數據......現在我已經沒有問題,從存儲箱中的數據,但之後關閉Swing對話框,進行的操作
操作後如何關閉此對話框?
似乎是一個簡單的事情,但我還沒有找到解決方案。
public class test extends JDialog {
private final JPanel contentPanel = new JPanel();
public test() {
setBounds(100, 100, 450, 300);
getContentPane().setLayout(new BorderLayout());
contentPanel.setLayout(new FlowLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("OK");
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
try{
int x=Integer.parseInt(textField.getText());
saver.saveN(x);
}catch(Exception ecc){
JOptionPane.showMessageDialog(Test.this,"error");
}
}
});
}
}
}
}
很好的答案+1 – mKorbel 2012-04-07 20:02:52
我不能使用的Dispose()這個元素contentPanel.setVisible(假)上,如果我使用;隱藏對話框的所有內容,但窗口仍然打開...出了什麼問題? – AndreaF 2012-04-07 20:28:57
@AndreaF你正在調用'contentPanel'上的方法,而不是'JDialog'。由於你的類從'JDialog'擴展,調用'this.dispose()'或'this.setVisible(false)'。 – Jeffrey 2012-04-07 20:33:03