Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6506360

RFE: need a public API to make a model internal frame

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P5
    • Resolution: Unresolved
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: client-libs

      Description

      J2SE Version (please include all output from java -version flag):
      java version "1.6.0-rc"
      Java(TM) SE Runtime Environment (build 1.6.0-rc-b96)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b96, mixed mode, sharing)

      Does this problem occur on J2SE 1.4.x or 5.0.x ? Yes / No (pick one)
      Yes

      Operating System Configuration Information (be specific):
      Microsoft Windows 2000 [Version 5.00.2195]

      New a public API to make a model internal frame

      When moving the mouse over JPopupMenu items within modal JInternalFrames, the selection
      does not change (we can still change the selection with the keyboard).
       JOptionPane puts
      a ClientProperty PopupFactory.forceHeavyWeightPopupKey to workaround the problem.
      However we don't even have access to this field as it is not public, and the fact that
      it wont work without it is not clearly documented.

      A workaround is to uncomment the 5 lines below (imitating what JOptionPane does).

      1) Run Code
      2) Click the Show Dialog button
      3) Click the Show Popup Menu button
      4) Move the mouse over Two or Three

      import static javax.swing.JFrame.*;
      import java.awt.*;
      import java.awt.event.*;
      import java.lang.reflect.*;
      import javax.swing.*;

      public class Test {
        public static void main(String[] args) {
          JInternalFrame internalFrame = new JInternalFrame();
          internalFrame.add(new JButton(new AbstractAction("Show Dialog") {
            public void actionPerformed(ActionEvent anEvent) {
              JInternalFrame internalFrame = new JOptionPane(new JButton(new AbstractAction("Show Popup Menu") {
                public void actionPerformed(ActionEvent anEvent) {
                  JPopupMenu popupMenu = new JPopupMenu();
                  popupMenu.add("One");
                  popupMenu.add("Two");
                  popupMenu.add("Three");
                  popupMenu.show((JButton)anEvent.getSource(), 10, 10);
                }
              })).createInternalFrame((JButton)anEvent.getSource(), "Dialog");
              internalFrame.setSize(400, 400);
              internalFrame.setVisible(true);
      // internalFrame.putClientProperty(new Object() {
      // public boolean equals(Object anObject) {
      // return anObject instanceof StringBuffer && "__force_heavy_weight_popup__".equals(anObject.toString());
      // }
      // }, true);
              try { // this makes the frame modal, using reflection in the same way JOptionPane does
                Method method = Container.class.getDeclaredMethod("startLWModal", (Class[])null);
                method.setAccessible(true);
                method.invoke(internalFrame, (Object[])null);
              }
              catch (Exception ex) {
              }
            }
          }));
          JDesktopPane desktopPane = new JDesktopPane();
          desktopPane.add(internalFrame);
          internalFrame.setSize(400, 400);
          internalFrame.setVisible(true);
          JFrame frame = new JFrame();
          frame.add(desktopPane);
          frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
          frame.setSize(600, 600);
          frame.setVisible(true);
        }
      }

        Attachments

          Activity

            People

            Assignee:
            mbronsonsunw Mike Bronson (Inactive)
            Reporter:
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: