This discussion is archived
0 Replies Latest reply: Apr 2, 2007 2:11 AM by 807596 RSS

EventDispatching with JDialogs (modal - alwaysOnTop)

807596 Newbie
Currently Being Moderated
I'm playing around with dispatching events in several JDialogs. This is what I want to do:
I have the main application Frame with some JTables with data. I'm opening a JDialog, that is set alwaysOnTop, because i'll drag&drop items from the table into it.

The problem appears, when i open a modal Dialog on the table header for a search. there are no events dispatched to my alwaysOnTop-Dialog. If things are bad, this popup Dialog is behind the alwaysOnTop Dialog and I cant close any of them.

Here's a small code sample, that shows my problem:

If you click in the Dialog1, a popup Dialog appears and you cant move the second dialog. When you click in the popup Dialog, it disappears and everything works fine.

So how can this problem be solved?
When the popup Dialog is shown, i still need to control the second dialog. I tried to open it from a new thread but it doesnt change things.
Any ideas?


    JDialog dialog1;
    JDialog dialog2;
    JDialog popup;
    InternalMouseAdapter internalMouseAdapter = new InternalMouseAdapter();


    public static void main(String[] args) {
        Test test = new Test();
        test.eventProblem();
    }

    public void eventProblem(){
        dialog1 = new JDialog((Frame)null,"Dialog1");
        dialog2 = new JDialog((Frame)null,"Dialog2");
        dialog1.setLocation(0,0);        dialog1.setSize(500,500);
        dialog2.setLocation(400, 400);   dialog2.setSize(100,100);
        dialog2.setAlwaysOnTop(true);
        dialog1.addMouseListener(internalMouseAdapter);
        dialog2.addMouseListener(internalMouseAdapter);
        dialog1.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        dialog2.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        dialog1.setVisible(true);
        dialog2.setVisible(true);
    }
    public class InternalMouseAdapter extends MouseAdapter{
        public void mouseClicked(MouseEvent e) {
            if(e.getSource() == dialog1){
                popup = new JDialog(dialog1,"popup",true);
                popup.addMouseListener(internalMouseAdapter);
                popup.setSize(50,50);
                popup.setLocation(100, 100);
                popup.setVisible(true);
            }
            else if(e.getSource()==popup){
                popup.setVisible(false);
            }
        }

    }