我试图JDialog
在JFrame
按下a 中的按钮时打开 a并且该对话框应包含JTable
.
我应该在哪里创建对话框(在框架内还是应该创建一个新类)?
如果您的对话框相当复杂,请为它使用一个新类。做类似的事情
public class OtherDialog extends JDialog {
// ...
public OtherDialog(){
// build dialog
}
}
并在您的 JFrame-Button-Actionhandler 中打开它,如下所示:
protected void btnOpenotherdialogActionPerformed(ActionEvent e) {
try {
OtherDialog dialog = new OtherDialog();
dialog.setModalityType(ModalityType.APPLICATION_MODAL);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception ex) {
ex.printStackTrace();
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句