diff options
Diffstat (limited to 'libjava/classpath/javax/swing/JOptionPane.java')
-rw-r--r-- | libjava/classpath/javax/swing/JOptionPane.java | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/libjava/classpath/javax/swing/JOptionPane.java b/libjava/classpath/javax/swing/JOptionPane.java index 88fa993be00..ad0772ab8d3 100644 --- a/libjava/classpath/javax/swing/JOptionPane.java +++ b/libjava/classpath/javax/swing/JOptionPane.java @@ -384,8 +384,8 @@ public class JOptionPane extends JComponent implements Accessible } /** - * This method creates a new JInternalFrame that is in the JDesktopPane - * which contains the parentComponent given. If no suitable JDesktopPane + * This method creates a new JInternalFrame that is in the JLayeredPane + * which contains the parentComponent given. If no suitable JLayeredPane * can be found from the parentComponent given, a RuntimeException will be * thrown. * @@ -395,25 +395,42 @@ public class JOptionPane extends JComponent implements Accessible * @return A new JInternalFrame based on the JOptionPane configuration. * * @throws RuntimeException If no suitable JDesktopPane is found. + * + * @specnote The specification says that the internal frame is placed + * in the nearest <code>JDesktopPane</code> that is found in + * <code>parent</code>'s ancestors. The behaviour of the JDK + * is that it actually looks up the nearest + * <code>JLayeredPane</code> in <code>parent</code>'s ancestors. + * So do we. */ public JInternalFrame createInternalFrame(Component parentComponent, String title) throws RuntimeException { - JDesktopPane toUse = getDesktopPaneForComponent(parentComponent); + // Try to find a JDesktopPane. + JLayeredPane toUse = getDesktopPaneForComponent(parentComponent); + // If we don't have a JDesktopPane, we try to find a JLayeredPane. + if (toUse == null) + toUse = JLayeredPane.getLayeredPaneAbove(parentComponent); + // If this still fails, we throw a RuntimeException. if (toUse == null) - throw new RuntimeException("parentComponent does not have a valid parent"); + throw new RuntimeException + ("parentComponent does not have a valid parent"); JInternalFrame frame = new JInternalFrame(title); inputValue = UNINITIALIZED_VALUE; value = UNINITIALIZED_VALUE; + frame.setContentPane(this); frame.setClosable(true); + toUse.add(frame); + frame.setLayer(JLayeredPane.MODAL_LAYER); + + frame.pack(); + frame.setVisible(true); - // FIXME: JLayeredPane broken? See bug # 16576 - // frame.setLayer(JLayeredPane.MODAL_LAYER); return frame; } @@ -1102,7 +1119,7 @@ public class JOptionPane extends JComponent implements Accessible JOptionPane pane = new JOptionPane(message); JInternalFrame frame = pane.createInternalFrame(parentComponent, null); - startModal(frame, pane); + startModal(frame); return ((Integer) pane.getValue()).intValue(); } @@ -1127,7 +1144,7 @@ public class JOptionPane extends JComponent implements Accessible JOptionPane pane = new JOptionPane(message, PLAIN_MESSAGE, optionType); JInternalFrame frame = pane.createInternalFrame(parentComponent, title); - startModal(frame, pane); + startModal(frame); return ((Integer) pane.getValue()).intValue(); } @@ -1153,7 +1170,7 @@ public class JOptionPane extends JComponent implements Accessible JOptionPane pane = new JOptionPane(message, messageType, optionType); JInternalFrame frame = pane.createInternalFrame(parentComponent, title); - startModal(frame, pane); + startModal(frame); return ((Integer) pane.getValue()).intValue(); } @@ -1181,7 +1198,7 @@ public class JOptionPane extends JComponent implements Accessible JOptionPane pane = new JOptionPane(message, messageType, optionType, icon); JInternalFrame frame = pane.createInternalFrame(parentComponent, title); - startModal(frame, pane); + startModal(frame); return ((Integer) pane.getValue()).intValue(); } @@ -1204,7 +1221,7 @@ public class JOptionPane extends JComponent implements Accessible pane.setWantsInput(true); JInternalFrame frame = pane.createInternalFrame(parentComponent, null); - startModal(frame, pane); + startModal(frame); return (String) pane.getInputValue(); } @@ -1230,7 +1247,7 @@ public class JOptionPane extends JComponent implements Accessible pane.setWantsInput(true); JInternalFrame frame = pane.createInternalFrame(parentComponent, title); - startModal(frame, pane); + startModal(frame); return (String) pane.getInputValue(); } @@ -1265,7 +1282,7 @@ public class JOptionPane extends JComponent implements Accessible pane.setInitialSelectionValue(initialSelectionValue); JInternalFrame frame = pane.createInternalFrame(parentComponent, title); - startModal(frame, pane); + startModal(frame); return (String) pane.getInputValue(); } @@ -1284,7 +1301,7 @@ public class JOptionPane extends JComponent implements Accessible JOptionPane pane = new JOptionPane(message); JInternalFrame frame = pane.createInternalFrame(parentComponent, null); - startModal(frame, pane); + startModal(frame); } /** @@ -1304,7 +1321,7 @@ public class JOptionPane extends JComponent implements Accessible JOptionPane pane = new JOptionPane(message, messageType); JInternalFrame frame = pane.createInternalFrame(parentComponent, title); - startModal(frame, pane); + startModal(frame); } /** @@ -1326,7 +1343,7 @@ public class JOptionPane extends JComponent implements Accessible pane.setIcon(icon); JInternalFrame frame = pane.createInternalFrame(parentComponent, title); - startModal(frame, pane); + startModal(frame); } /** @@ -1358,7 +1375,7 @@ public class JOptionPane extends JComponent implements Accessible JInternalFrame frame = pane.createInternalFrame(parentComponent, title); - startModal(frame, pane); + startModal(frame); return ((Integer) pane.getValue()).intValue(); } @@ -1509,15 +1526,8 @@ public class JOptionPane extends JComponent implements Accessible * @param f The JInternalFrame to make modal. * @param pane The JOptionPane to add to the JInternalFrame. */ - private static void startModal(JInternalFrame f, JOptionPane pane) + private static void startModal(JInternalFrame f) { - f.getContentPane().add(pane); - f.pack(); - f.show(); - - Dimension pref = f.getPreferredSize(); - f.setBounds(0, 0, pref.width, pref.height); - synchronized (f) { final JInternalFrame tmp = f; |