Second JOptionPane Focus Problem

Hi,

When I try to show another JOptionPane after the first one it loses focus. The first one doesnt have this focus problem.

String name = JOptionPane.showInputDialog(frm,"Enter Name:","MyApp",JOptionPane.INFORMATION_MESSAGE);

String number = JOptionPane.showInputDialog(frm,"Enter Number:","MyApp",JOptionPane.INFORMATION_MESSAGE);

[457 byte] By [cxno3a] at [2007-10-3 4:32:19]
# 1

When you have a bug like this, convert it to an executable example as below. Makes life easier for all of us and you'll often even spot the problem before needing to post.

Anyway, it works for me. I'm laying money you're calling it outside the event dispatch thread.

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.SwingUtilities;

public class Focus implements Runnable

{

public static void main(String[] args)

{

SwingUtilities.invokeLater(new Focus());

}

public void run()

{

JFrame frm = new JFrame();

frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frm.getContentPane().add(new JLabel("Hello"));

frm.pack();

frm.setLocationRelativeTo(null);

frm.setVisible(true);

String name = JOptionPane.showInputDialog(frm,"Enter Name:","MyApp",JOptionPane.INFORMATION_MESSAGE);

String number = JOptionPane.showInputDialog(frm,"Enter Number:","MyApp",JOptionPane.INFORMATION_MESSAGE);

}

}

itchyscratchya at 2007-7-14 22:35:50 > top of Java-index,Desktop,Core GUI APIs...
# 2

After a couple of tests I have found that the problem is from the LookAndFeel I have been using (SkinLF). When I disable SkinLF it is OK. Any Ideas ? It looks like the problem originates from these 3 lines in the constructor to enable SkinLF on the JFrame.

frm.setUndecorated(true);

frm.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);

frm.setDefaultLookAndFeelDecorated(true);

btw sorry itchyscratchy and others, I should have found it sooner :(

cxno3a at 2007-7-14 22:35:50 > top of Java-index,Desktop,Core GUI APIs...