JDK-4974162 : Two tabs are selected when Look and feel is changed to Synth.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2004-01-06
  • Updated: 2004-08-26
  • Resolved: 2004-08-26
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
First Tab will always be selected when Look and feel is changed to Synth.

Steps to reproduce:
-------------------
1) Unzip the Attached Zip file and compile and execute SynthTest.java .
2)Click on tab number 2.Change the Look and Feel to synth.
3)Notice that the First tab as well as the tab number 2 have bold Font. This font is selected tab.
This is done on build 32.

Comments
EVALUATION Name: omR10226 Date: 02/10/2004 Looks like a bug. ====================================================================== Name: ibR10256 Date: 03/30/2004 There are two points that cause the problem: 1. focusIndex is initialized to ZERO in BasicTabbedPaneUI. Zero is the index of the first tab. When LF is switched to Synth a new UI is created: so the first tab becomes "focused" even if another tab is selected at the time of the switch. 2. DefaultSynthStyle.getFont() implementation has the following check: if the state of the region equals ENABLED, the tabbedPane.getFont() font is used, otherwise the call is delegated to getFontForState() which fetches the font out of the StateInfo[]. If, for instance, the second tab was selected before the LF switch, then it stays ENABLED|SELECTED and the first tab becomes ENABLED|FOCUSED after the switch. Both these states are not equal to ENABLED, so for them the font defined in SynthTest.xml is used (it's bold), for the others (which have status ENABLED) the component's font is used. This makes an impression that the both first two tabs are selected. So, I think, first, when LF is switched focusIndex should be reset to -1 (not to zero). In this case it will be set to the selected tab index upon BasicTabbedPaneUI.focusGained(). Second, the DefaultSynthStyle.getFont() logic should be verified. ###@###.### 2004-03-26 ====================================================================== Name: ibR10256 Date: 04/09/2004 The suggested fix applies to the first issue pointed out in my evaluation. A new bug: 5029514 is filed to solve the second issue. ###@###.### 2004-04-09 ====================================================================== Name: ibR10256 Date: 04/19/2004 The original suggested fix leads the regression test for 4361477 (javax/swing/JTabbedPane/4361477) to failure. So it needs to be modified. In javax.swing.plaf.basic.BasicTabbedPaneUI$Handler.mousePressed() if the selected tab is changed the old focused tab is repainted. In the 4361477 test case the old focused tab is removed before this mousePressed method is invoked, so the following exception is thrown: Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 2 at javax.swing.plaf.basic.BasicTabbedPaneUI.getTabBounds(BasicTabbedPaneUI.java:1323) at javax.swing.plaf.basic.BasicTabbedPaneUI.getTabBounds(BasicTabbedPaneUI.java:1258) at javax.swing.plaf.basic.BasicTabbedPaneUI$Handler.mousePressed(BasicTabbedPaneUI.java:3230) at java.awt.Component.processMouseEvent(Component.java:5462) at javax.swing.JComponent.processMouseEvent(JComponent.java:3121) at java.awt.Component.processEvent(Component.java:5230) at java.awt.Container.processEvent(Container.java:1961) at java.awt.Component.dispatchEventImpl(Component.java:3933) at java.awt.Container.dispatchEventImpl(Container.java:2019) at java.awt.Component.dispatchEvent(Component.java:3781) 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:1764) at java.awt.Component.dispatchEvent(Component.java:3781) 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) This happens only when focusIndex is properly initialized. But that's not the case with 4361477 without the original fix for 4974162 being applied: in this case focusIndex is always 0 and so is not repainted. So I think, we should still properly initialize focusIndex but we shouldn't attempt to repaint the old focused tab on selection change if the old selected tab doesn't exist anymore. ###@###.### 2004-04-19 ====================================================================== When the fix for this is ready, we should verify that it solves 5048287 - which I've just closed as a duplicate. ###@###.### 2004-05-18 This has been fixed as part of 5056403, refer to it for details. ###@###.### 2004-08-26
18-05-2004

SUGGESTED FIX Name: ibR10256 Date: 04/09/2004 *** BasicTabbedPaneUI.java- Thu Apr 8 12:43:08 2004 --- BasicTabbedPaneUI.java Thu Apr 8 12:02:00 2004 *************** *** 191,199 **** --- 191,204 ---- this.tabPane = (JTabbedPane)c; rolloverTabIndex = -1; + focusIndex = -1; c.setLayout(createLayoutManager()); installComponents(); installDefaults(); + if (DefaultLookup.getBoolean(tabPane, this, + "TabbedPane.selectionFollowsFocus", true)) { + focusIndex = ((JTabbedPane) c).getSelectedIndex(); + } installListeners(); installKeyboardActions(); } ###@###.### 2004-04-09 ======================================================================
09-04-2004