甄士隐
甄士隐

Reputation: 31

Java How to pass doubleclick events result in non-modal Dialog to parents Frame?

My design is JFrame generate a non-modal Jdialog. and there is a Jtable in the Jdialog. Some search results will be displayed in the Jtable.

My question is I add a double-click mouse action to the Jtable which will get an ID value from the Jtable column. How can I pass the ID value to JFrame? There is a Jcombobox in the JFrame which I would like to set the ID value to it and will display more information about the ID in JFrame.

Hope I have expressed clearly. Thanks for help in advance.

Upvotes: 1

Views: 62

Answers (1)

Gulllie
Gulllie

Reputation: 558

You could pass your JComboBox into you JDialog's constructor, then, after you get the ID you'd be able to call methods on the JComboBox to add the ID. Example:

    JComboBox comboBox;

    public YourDialogName(JComboBox comboBox /*All the rest of the parameters*/){
    this.comboBox = comboBox;
    //Do other stuff...
    }

    private void addIDToComboBox(String id){
        comboBox.addItem(id);   //Change to however to want to add your ID
    }

There could definitely be a better solution though.

Upvotes: 2

Related Questions