Name: dmR10075 Date: 03/23/2004 If JOptionPane is used to create input dialog using a static method, and as a message some JComponent is provided, there is no way to set focus to this component upon JOptionPane showing. It always sets focus to default button. I think it is an overkill - default button will anyway be pressed if user presses Enter, but the focus should instead go to the default component in a Window. To implement this, JOptionPane just shouldn't request focus at all and focus subsystem will do the rest. As an option, JOptionPane can modify focus traversal policy to indicate that default button is in fact default focus component. Another possibility might be to request focus to default button(if it is still necessary, for example, for some L&F), but do this BEFORE message is added so that there is a way to request focus to the user's component on some event(SHOWING, for example) after the request to default button. If any workaround is possible, please indicate that. Below is the test case: import javax.swing.*; import java.awt.FlowLayout; public class JOptionPaneFocus { public static void main(String[] args) { JPanel panel = new JPanel(); JButton button = new JButton("Focus"); panel.setLayout(new FlowLayout()); panel.add(button); JOptionPane.showOptionDialog(null, panel, "Check focus", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); } } ======================================================================
|