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

REGRESSION: JTabbedPane setFocusable(false) and removing tabs

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta
    • CPU:
      generic, x86
    • OS:
      generic, windows_xp

      Backports

        Description



        Name: gm110360 Date: 06/02/2004


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

        ADDITIONAL OS VERSION INFORMATION :
        Windows XP Home

        A DESCRIPTION OF THE PROBLEM :
        An exception is thrown when a tab is removed from a tabbedpane and another tab is selected after tabbedPane.setFocusable(false) has been called.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the example prog given. Close the 3rd tab by right clicking on it and selecting close. Then Click on the second tab and an exception will be thrown.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        No exception.
        ACTUAL -
        Exception is thrown, no functionality difference that I can see.

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        java.lang.ArrayIndexOutOfBoundsException: 2
        at javax.swing.plaf.basic.BasicTabbedPaneUI.getTabBounds(BasicTabbedPaneUI.java:1297)
        at javax.swing.plaf.basic.BasicTabbedPaneUI.getTabBounds(BasicTabbedPaneUI.java:1237)
        at javax.swing.plaf.basic.BasicTabbedPaneUI$Handler.mousePressed(BasicTabbedPaneUI.java:3200)
        at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:221)
        at java.awt.Component.processMouseEvent(Component.java:5460)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3052)
        at java.awt.Component.processEvent(Component.java:5228)
        at java.awt.Container.processEvent(Container.java:1961)
        at java.awt.Component.dispatchEventImpl(Component.java:3931)
        at java.awt.Container.dispatchEventImpl(Container.java:2019)
        at java.awt.Component.dispatchEvent(Component.java:3779)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4203)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3880)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3813)
        at java.awt.Container.dispatchEventImpl(Container.java:2005)
        at java.awt.Window.dispatchEventImpl(Window.java:1757)
        at java.awt.Component.dispatchEvent(Component.java:3779)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.awt.*;
        import java.awt.event.*;
        import javax.swing.*;
        import javax.swing.event.*;

        class TabbedPaneBug extends JFrame
        {
        JTabbedPane tabbedPane=new JTabbedPane(JTabbedPane.BOTTOM);
        JPopupMenu popupMenu;
        public TabbedPaneBug()
        {
        tabbedPane.setFocusable(false);
        JLabel label1=new JLabel("Label1"), label2=new JLabel("Label2"), label3=new JLabel("Label3");
        popupMenu=new JPopupMenu();
        JMenuItem closeTab=new JMenuItem("Close");
        PopupListener pl=new PopupListener();
        closeTab.addActionListener(pl);
        popupMenu.add(closeTab);
        tabbedPane.addMouseListener(pl);
        tabbedPane.addTab("Title1", label1);
        tabbedPane.addTab("Title2", label2);
        tabbedPane.addTab("Title3", label3);
        getContentPane().add(tabbedPane);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(500,500);
        setVisible(true);
        }
        public static void main(String args[])
        {
        new TabbedPaneBug();
        }
        class PopupListener implements MouseListener, ActionListener
        {
        int x,y;
        public void actionPerformed(ActionEvent e)
        {
        final int index=tabbedPane.indexAtLocation(x,y);
        //This is where I think the problem is, it seems like a syncronization problem, which
        //is why I forced it to remove the tab in the event thread, but that didn't help.
        tabbedPane.removeTabAt(index);
        }
        public void mouseEntered(MouseEvent e){}
        public void mouseExited(MouseEvent e){}
        public void mouseClicked(MouseEvent e)
                 {showPopup(e);}
        public void mousePressed(MouseEvent e)
                 {showPopup(e);}
        public void mouseReleased(MouseEvent e)
                 {showPopup(e);}
             private void showPopup(MouseEvent e)
             {
        x=e.getX();
        y=e.getY();
                 if (e.isPopupTrigger()&&tabbedPane.indexAtLocation(x,y)>=0)
                     popupMenu.show(e.getComponent(),e.getX(), e.getY());
             }
        }
        }

        ---------- END SOURCE ----------

        Release Regression From : 1.4.2
        The above release value was the last known release where this
        bug was known to work. Since then there has been a regression.

        (Incident Review ID: 275928)
        ======================================================================

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                svioletsunw Scott Violet (Inactive)
                Reporter:
                gmanwanisunw Girish Manwani (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: