1

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:

  • I want to make it visible with the right attributes. So I need to put something at the (...,...) constructor... but I have no clue what I have to put there.
  • I want to give a String id (which contains the ID what the Jdialog needs to print the right values)

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:

  • incompatible types < anonymous ClickListener > cannot be converted to Frame
Danny Hoeve
  • 692
  • 13
  • 30
  • In your `doubleCLick` method you should invoke `.setVisible()` in the created instance. Actually, providing code for `InzienSelectieDialoog ` would help here a lot. – Ostap Andrusiv May 25 '14 at 12:01
  • Use the parent `JFrame` as 'variable' to pass the dialog. See also [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) – Andrew Thompson May 25 '14 at 12:02
  • 1
    @OstapAndrusiv *"providing code for .. would help here a lot"* What would help *most* is an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete and Verifiable Example). ;) – Andrew Thompson May 25 '14 at 12:04
  • @OstapAndrusiv I'm not sure whether I need to provide more than I already gave. The constructor and the runnable are the only two that are causing problems. – Danny Hoeve May 25 '14 at 12:29
  • 1
    @DannyHoeve that's ok, haven't seen `InzienSelectieDialoog` costructor back then. – Ostap Andrusiv May 26 '14 at 08:34

1 Answers1

1

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.

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
  • This is something the Design Mode does for me. As I'm not very familar with everything that it does I also don't want to delete most of it because it works like it does. I did delete it in the JDialog and got the the JDialog working now. Thanks – Danny Hoeve May 25 '14 at 13:07