I have a GUI which consist of a JLabel named "View":
with a mouseClickEvent attached to it. Upon clicking on the "View" JLabel, i can open multiple instances of a modeless JDialog.
The JDialog itself consist of several disabled JTextFields and a JLabel with a mouseClickEvent attached to it which act as a "Close" button:
However upon opening more than one JDialog, the "close" JLabel is disabled and the mouseClickEvent does not work anymore.
Here is my code:
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();
}
Is there a way to open multiple instances while still retaining the mouseClickEvent of the "close" JLabel in each opened instance of the JDialog?