【发布时间】:2020-08-18 17:50:43
【问题描述】:
我有一个由名为“View”的 JLabel 组成的 GUI:
附加了一个mouseClickEvent。单击“查看”JLabel 后,我可以打开无模式 JDialog 的多个实例。
JDialog 本身由几个禁用的 JTextField 和一个带有 mouseClickEvent 的 JLabel 组成,它充当“关闭”按钮:
但是,在打开多个 JDialog 时,“关闭”JLabel 被禁用,并且 mouseClickEvent 不再起作用。
这是我的代码:
private void viewDoctorClickedEvent(java.awt.event.MouseEvent evt)
{
javax.swing.JFrame topFrame = (javax.swing.JFrame)
javax.swing.SwingUtilities.getWindowAncestor(this);
viewDoctorDialog = new javax.swing.JDialog(topFrame, "View Doctor Details", false);
viewDoctorDialog.setMinimumSize(new java.awt.Dimension(580, 350));
viewDoctorDialog.setResizable(false);
viewDoctorDialog.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
viewDoctorDialog.setLocationRelativeTo(topFrame);
// This part is used to collect the values from the selected row of a Jtable and set the
// values to the disabled JTextFields in the JDialog
try
{
int selectedTableRow = doctorListTB.getSelectedRow();
String doctorName = doctorListTB.getValueAt(selectedTableRow, 0).toString();
String doctorEmail = doctorListTB.getValueAt(selectedTableRow, 1).toString();
String doctorPassword = doctorListTB.getValueAt(selectedTableRow, 2).toString();
String doctorAddress = doctorListTB.getValueAt(selectedTableRow, 3).toString();
String doctorPhone = doctorListTB.getValueAt(selectedTableRow, 4).toString();
String doctorDepartment = doctorListTB.getValueAt(selectedTableRow, 5).toString();
viewDoctorNameTF.setText(doctorName);
viewDoctorEmailTF.setText(doctorEmail);
viewDoctorPasswordTF.setText(doctorPassword);
viewDoctorAddressTF.setText(doctorAddress);
viewDoctorPhoneTF.setText(doctorPhone);
viewDoctorDepartmentTF.setText(doctorDepartment);
viewDoctorDialog.add(viewDoctorDialogPanel);
viewDoctorDialog.setVisible(true);
}
catch(Exception e)
{
javax.swing.JOptionPane.showMessageDialog(viewDoctorDialogPanel, "Please select a row to view.", "No data to view.", javax.swing.JOptionPane.ERROR_MESSAGE);
}
}
// Mouse Click Event to close the JDialog upon clicking on the "close" JLabel
private void closeViewButtonClickedEvent(java.awt.event.MouseEvent evt)
{
viewDoctorDialog.dispose();
}
有没有办法打开多个实例,同时在每个打开的 JDialog 实例中仍保留“关闭”JLabel 的 mouseClickEvent?
【问题讨论】:
-
也许是edit你的问题并发布minimal reproducible example?
-
你用tour了吗?你去过Help Center吗?你读过这个吗:How do I ask a good question?