2

I have a weird problem with modal jdialog in windows xp. It seams i can't switch windows language with alt+shift while dialog is focused. I don't want parent frame to be accessible. Please help me.

public class MyDialog extends JDialog {
        public MyDialog(java.awt.Frame parent, boolean modal) {
            super(parent, modal);
            initComponents();
        }
        public static void main(String args[]) {   
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    MyDialog dialog = new MyDialog(new javax.swing.JFrame(), true);
                    dialog.setVisible(true);
                }
            });
        }
    }
BillRobertson42
  • 12,602
  • 4
  • 40
  • 57
Ivan Ivanovich
  • 227
  • 1
  • 3
  • 7

1 Answers1

3

I tried your example, without any success, Toolkit is never locked, Java6 on WinXp / Win2008

same for

  • AWT Frame with AWT Dialog

  • AWT Frame with Swing JDialog

  • Swing JFrame with Swing JDialog

  • Swing JFrame with AWT Dialog

based on code example

import javax.swing.JDialog;
import javax.swing.JFrame;

public class MyDialog {

    private JFrame frame = new JFrame();
    private JDialog dialog = new JDialog();

    public MyDialog() {
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 300);
        frame.setVisible(true);
        //dialog = new JDialog(frame, JDialog.ModalityType.TOOLKIT_MODAL);
        dialog = new JDialog(frame, true);
        dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        dialog.setModal(true);
        dialog.setSize(300, 200);
        dialog.setVisible(true);
    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                MyDialog dialog = new MyDialog();
            }
        });
    }
}  
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • Thanks ! My problems appears if i comment out `frame.setVisible(true);` Why? – Ivan Ivanovich Mar 22 '12 at 14:16
  • maybe because you mixing AWT Frame with Swing JDialog :-), better would be use same Components type, I tried that too, without success :-) – mKorbel Mar 22 '12 at 14:20
  • Please bear with me. I don't understand where i am mixing Frame and JDialog? What i need to change in my code? – Ivan Ivanovich Mar 22 '12 at 14:26
  • @Ivan Ivanovich I think that correct constructor should be `public MyDialog(JFrame parent, boolean modal) {` sure if there any JFrame exist, – mKorbel Mar 22 '12 at 14:38
  • so if JFrame is not visible it not "exists"? I'm trying to use code you posted. Please help me to understand. – Ivan Ivanovich Mar 22 '12 at 14:41
  • rest here [Mixing heavy and light components](http://java.sun.com/products/jfc/tsc/articles/mixing/) – mKorbel Mar 22 '12 at 14:41
  • JFrame exist in my example, in both cases if is Visible or if you disable `//frame.setVisible(true);` then exist too, declare `private JFrame frame = new JFrame();` created a new instance, – mKorbel Mar 22 '12 at 14:44
  • I still don't understand why if parent frame is invisible, i can't change language in os :( – Ivan Ivanovich Mar 22 '12 at 14:51