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

Focus problem when poping up a menu and selecting a JInternalFrame

XMLWordPrintable



      Name: jk109818 Date: 07/15/2002


      FULL PRODUCT VERSION :
      java version "1.4.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
      Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      4NT 3.02B Windows NT 5.00

      A DESCRIPTION OF THE PROBLEM :
      When switching between internal frames, using the right
      mosue button and poping up a menu at the same time, focus
      is not going to the popup menu.

      This causes focus problems when using the arrow keys. Focus
      is going to the invoker control, not the menu.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile and run the attached code
      2. Right click on the second tree to get the popup menu
      3. Press the down-arrow key.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Actual:
      The nodes on the tree view are getting selected.

      Expected:
      The items in the popup menu should be getting selected.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import java.awt.*;
      import java.awt.image.*;
      import java.text.*;
      import java.awt.event.*;
      import javax.swing.text.*;
      import javax.swing.*;
      import javax.swing.event.*;
      import javax.swing.border.*;

      public class Frame1 extends JFrame {

      JPanel contentPane;
      BorderLayout borderLayout1 = new BorderLayout();
      JDesktopPane desktop = new JDesktopPane();
      JPanel jPanel1 = new JPanel();
      JTextArea ta = new JTextArea();
      JInternalFrame jif1;
      JInternalFrame jif2;

      public static void main(String[] args) {
      try {
      UIManager.setLookAndFeel
      (UIManager.getSystemLookAndFeelClassName());
      }
      catch(Exception e) {
      e.printStackTrace();
      }
      Frame1 frame = new Frame1();
      frame.setLocation(100, 100);
      frame.setVisible(true);
      }

      public Frame1() {
      enableEvents(AWTEvent.WINDOW_EVENT_MASK);
      contentPane = (JPanel)getContentPane();
      contentPane.setLayout(borderLayout1);
      setSize(new Dimension(600, 300));
      setTitle("Focus Issue");
      contentPane.add(desktop);
      jif1 = new JInternalFrame("Frame1", true, true, true, true);
      jif1.setBounds(10, 10, 200, 100);
      JTree t1 = new JTree();
      final JTree t2 = new JTree();
      JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
      true, t1, t2);
      jPanel1.add(sp);
      jif1.getRootPane().setFocusable(false);
      jif1.getContentPane().add(jPanel1, BorderLayout.NORTH);
      jif1.show();

      jif2 = new JInternalFrame("Frame2", true, true, true, true);
      jif2.setBounds(210, 10, 100, 100);
      jif2.getRootPane().setFocusable(false);
      jif2.getContentPane().add(ta, BorderLayout.NORTH);
      jif2.show();
      t2.addMouseListener(new MouseAdapter() {
      public void mouseReleased(MouseEvent e) {
      JPopupMenu pm = new JPopupMenu();
      pm.add("Hi"); pm.add("Yo");
      pm.show(t2, e.getX(), e.getY());
      }
      });

      setupFocusTimer();

      desktop.add(jif1);
      desktop.add(jif2);
      // switch focus to the second internal frame for this demo
      addWindowListener(new WindowAdapter() {
      public void windowOpened(WindowEvent e) {
      activateFrame(jif2);
      ta.requestFocusInWindow();
      }
      });
      }

      ////////////////////////////
      ////////////////////////////
      // helper functions
      ////////////////////////////
      ////////////////////////////


      static public void restoreFrame(JInternalFrame jif) {
      try {
      if (jif.isIcon()) {
      jif.setIcon(false);
      }
      }
      catch (java.beans.PropertyVetoException pve) {
      pve.printStackTrace();
      }
      }

      static public void selectFrame(JInternalFrame jif) {
      try {
      jif.setSelected(true);
      }
      catch (Exception e) {
      e.printStackTrace();
      }
      }

      static public void activateFrame(final JInternalFrame jif) {
      jif.setVisible(true);
      restoreFrame(jif);
      jif.moveToFront();
      selectFrame(jif);
      }

      private void setupFocusTimer() {
      // show current focus item
      javax.swing.Timer timer = new javax.swing.Timer(50, new
      ActionListener() {
      public void actionPerformed(ActionEvent e) {
      FocusManager fm = FocusManager.getCurrentManager
      ();
      Component c = fm.getFocusOwner();
      JInternalFrame jif = desktop.getSelectedFrame();
      String s = "Focus = ";
      if (c == null) {
      s += "null";
      }
      else {
      String s2 = c.toString();
      s += s2.substring(0, s2.indexOf('['));
      }
      s += "; Frame = ";
      if (jif == null) {
      s += "null";
      }
      else {
      String s2 = jif.toString();
      s += s2.substring(0, s2.indexOf
      ("layout="));
      }
      setTitle(s);
      }
      });
      timer.start();
      }

      protected void processWindowEvent(WindowEvent e) {
      super.processWindowEvent(e);
      if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
      }
      }
      }

      ---------- END SOURCE ----------
      (Review ID: 159380)
      ======================================================================

            shickeysunw Shannon Hickey (Inactive)
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: