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

Focus from popup text area moves to component of container while popup is still there

    XMLWordPrintable

    Details

      Description

      OPERATING SYSTEM(S): Windows XP

      FULL JDK VERSION(S):
      java version "1.5.0_08"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
      Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode)

      DESCRIPTION:
      When using the popup text area, the focus can be moved from the popup text area using the CTRL+TAB to the first component of the container even when the popup is still there. We believe that the proper behavior of the popup should be NOT ABLE TO MOVE THE FOCUS ( using the CTRL + TAB ) from the popup until it disappears either by selecting any of the menu items or by pressing the ESC key.

      The above said "Expected Behavior" could be observed if the popup contains only menu items and menu seperators. ie., the focus could not be moved using CTRL + TAB to other components until the popup disappears. However if the popup contains a text area inside, then the focus could be moved using the CTRL + TAB keys while the popup is still there.

      - Exact steps to reproduce

      1. Run the following sample code:

      import java.awt.*;
      import javax.swing.*;
      import javax.swing.event.*;
      import javax.swing.text.Caret;
      import java.awt.Component;
      import java.awt.ContainerOrderFocusTraversalPolicy;
      import java.awt.DefaultFocusTraversalPolicy;
      import java.awt.FlowLayout;
      import java.awt.KeyboardFocusManager;
      import java.util.Comparator;


      import java.awt.event.*;


      class Testing extends JPanel {

      /**
      * @param args
      */

      JButton jButton;

      JTextArea jTextArea;


      Testing()
      {

      JFrame f=new JFrame("Sample");

                  KeyboardFocusManager kfm= KeyboardFocusManager.getCurrentKeyboardFocusManager();
      f.getContentPane().setLayout(new FlowLayout());

      f.getContentPane().add(new JButton("Test1"));

      jButton = new JButton("JButton");
      jButton.setName("Swing_Button");
      jButton.addActionListener(new JBListener());
      f.getContentPane().add(jButton);

      f.getContentPane().add(new JButton("Test2"));

      jTextArea = new JTextArea ();
      jTextArea.setName("JTextArea");
      jTextArea.setLineWrap(true);
      jTextArea.setRows(5);
      jTextArea.setWrapStyleWord(true);
      jTextArea.setMargin(new Insets(2, 4, 2, 4));
      //f.getContentPane().add(jTextArea);

      f.getContentPane().add(new JScrollPane(jTextArea));


      f.getContentPane().add(new JButton("Test3"));


      kfm.setDefaultFocusTraversalPolicy(new ContainerOrderFocusTraversalPolicy());

      f.setFocusTraversalPolicy(KeyboardFocusManager.getCurrentKeyboardFocusManager()
      .getDefaultFocusTraversalPolicy());
      f.setSize(100,100);
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f.setVisible(true);
      }
      public static void main(String[] args) {
      // TODO Auto-generated method stub
      new Testing ();
      }

      }

      class JBListener implements ActionListener {
      JPopupMenu popupMenu = new JPopupMenu();

      JTextArea ppFocusItem = new JTextArea();

      public JBListener() {
      ppFocusItem.setName("JTextArea");
      ppFocusItem.setLineWrap(true);
      ppFocusItem.setRows(5);
      ppFocusItem.setWrapStyleWord(true);
      ppFocusItem.setMargin(new Insets(2, 4, 2, 4));
      popupMenu.add(new JScrollPane(ppFocusItem));
      }

      public void actionPerformed(ActionEvent e) {
      JButton JB = (JButton) e.getSource();
      Point p = JB.getLocation();
      popupMenu.show(JB.getParent(), p.x, p.y + JB.getHeight());
      ppFocusItem.requestFocus();
      }
      }


       2. Click on button1.
       3. Press 'tab'. The focus moves to button2.
       4. Press 'spacebar'. The popup text area appears and focus will be in the popup text area.
       5. Press 'Ctrl+tab'. Observe that the focus moves to the scroll bar.
       6. Press 'tab' again. The focus moves to the button1 which is the first component of the container while the popup is still there.
       7. But instead of the text area inside the popup if you have a menu item, then you could see that you are not able to move the focus from the menu until the menu disappears either by selecting the menu item or by using the ESC key.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            elarsen Erik Larsen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: