Reputation: 722
I'm using Design mode on NetBeans in order to create multiple JFrames. I'm currently trying to make a JDialog but I don't know what kind of variable I have to give it.
Because Design-mode made the code for me, I can't just edit it in order to let it work. It was already quite the hassle to get a doubleClick event in the generated code of the masterTable.
this is the code I'm trying to run. The public void DoubleClick is where an new instance for the Jdialog is made.
masterTable.addMouseListener( new ClickListener() {
public void singleClick (MouseEvent e) {
System.out.println("single");
JTable target = (JTable) e.getSource();
int row = target.getSelectedRow();
int col = 0;
Object data = (Object) target.getValueAt(row, col);
String id = data.toString();
System.out.println("Er is geklikt op de rij met ID nummer: " + data);
try {
GetSelectedData(id);
} catch (SQLException ex) {
Logger.getLogger(InzienDienstgegevensForm.class.getName()).log(Level.SEVERE, null, ex);
}
try {
DisplayPaymentInfo(id);
} catch (SQLException ex) {
Logger.getLogger(InzienDienstgegevensForm.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void doubleClick (MouseEvent e){
System.out.println("double");
JTable target = (JTable) e.getSource();
int row = target.getSelectedRow();
int col = 0;
Object data = (Object) target.getValueAt(row, col);
String id = data.toString();
System.out.println("Er is geklikt op de rij met ID nummer: " + data);
InzienSelectieDialoog dialoog = new InzienSelectieDialoog(this, true);
}
});
My JDIALOG has the following constructor and runnable in public void Run():
public InzienSelectieDialoog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}
public static void main(String args[]) {
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
InzienSelectieDialoog dialog = new InzienSelectieDialoog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
There are two things I want to adjust in order for me to get this JDialog working like I want it to:
Any suggestion are very welcome!
If I need to provide more code or information what I want to do, please ask me and I'll do so accordingly.
EDIT: the masterTable.addMouseListener is inside the public void initComponents(). The this in the new JDialoog (InzienGegevensSelectie) gives the following error:
Upvotes: 1
Views: 732
Reputation: 208944
The this in the new JDialoog (InzienGegevensSelectie) gives the following error:
incompatible types < anonymous ClickListener > cannot be converted to Frame
new InzienSelectieDialoog(this, true);
You have created the dialog in the context of the ClickListener
. Meaning this
refers to the ClickListener
. To change the this
to the frame, you need to prefix the frame's class name like MyFrame.this
Side Note
I notice your dialog class has a main
method. You don't need that. Your application should only have one main
method, which is in the frame class. Get rid of the main
method, add the window listener and set it visible in the constructor.
I don't know why you are trying to instantiate the dialog in the main method of the dialog class. It should only need to be instantiate in from the frame class.
Upvotes: 1