JDK-7024235 : Nimbus L&F: wrong "packing" of a frame containing tabbed pane
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris
  • CPU: generic
  • Submitted: 2011-03-03
  • Updated: 2013-10-03
  • Resolved: 2013-09-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b110Fixed
Related Reports
Relates :  
Relates :  
Description
JDK: 6u10+, JDK7
L&F: 
  Fails: Nimbus
  Passed: others
OS: Solaris/GNOME

When calling pack() on a frame containing tabbed pane under Nimbus, not all the tabs are resized properly. 
Please see the attached screenshot that corresponds the following code sample.
It is extracted from JCK testcase.

------------------------------------------------------------------------------
import javax.swing.*;
import java.awt.*;
import java.lang.reflect.InvocationTargetException;

public class Test_indexAtLocation {

    public static void main(String[] args) throws InvocationTargetException, InterruptedException {

        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                final Component components[] = {new Container(), new JButton(), new JCheckBox()};
                final String names[] = {"1", "2", "3"};

                final JTabbedPane tabbedPane = new JTabbedPane();


                for (int j = 0; j < components.length; j++) {
                    tabbedPane.addTab(names[j], components[j]); // Fill the set
                }

                final JFrame fr = new JFrame();
                fr.getContentPane().add(tabbedPane);

                fr.pack();
                fr.setVisible(true);

                for (int i = 0; i < tabbedPane.getTabCount(); i++) {
                    Rectangle rr = tabbedPane.getBoundsAt(i);
                    int index = tabbedPane.indexAtLocation(
                            rr.x + rr.width / 2, rr.y + rr.height / 2);
                    if (index != i) {
                        System.out.println("indexAtLocation returns " + index + " for pane, but " + i + " is expected for[" + i + "] = " + rr + "!");
                    }
                }
                System.out.println("OK");
            }
        });
    }

}
------------------------------------------------------------------------------

With -Dswing.defaultlaf=javax.swing.plaf.nimbus.NimbusLookAndFeel

the output will be:

indexAtLocation returns 1 for pane, but 2 is expected for[2] = java.awt.Rectangle[x=25,y=63,width=-7,height=22]!


The following JCK test fails with Nimbus
api/javax_swing/JTabbedPane/index2.html#various[JTabbedPane2302]

Comments
http://cr.openjdk.java.net/~malenkov/7024235.8.0/
19-09-2013

Removed affect version 7 as it was approved to deferral to JDK 8 and this sub CR is for JDK 8 only and 7u2 specific backport is closed.
09-07-2013

EVALUATION I'm closing subCR for 7u2 and accepting subCR for jdk8 because of following comment from Mathias: Bug deferral review: Approved for deferral to JDK 8. *** (#10 of 10): 2011-05-03 18:56:23 MSD ###@###.###
18-07-2011

EVALUATION Check the behavoiur if more components are there (don't miss the names[] as well). The essense of the changes is: final Component components[] = {new Container(), new JButton("hello"), new JCheckBox(), new JCheckBox(), new JCheckBox()}; final String names[] = {"1", "2", "3", "4", "5"}; In this case under Windows it renders components in two lines (3 and 2 comps in each) respectively. So generally speaking this problem might also be shown on windows (just use plain JWindow).
27-04-2011

EVALUATION The window on the pack() call seem doesn't take into account actual component's sizes. That's alright on windows because (just an assumption based on what I visually see under gnome and windows7) the client area within the window can't be shrinked even further because of the native window decorations (Max, Min, Close).
27-04-2011

EVALUATION problem is seen with code sample provided: ---------------------------------------------------------------------------------------------------------------- <db158260@spb-sapphire(pts/17).270> /set/java/re/jdk/7/promoted/latest/binaries/solaris-sparc/bin/java -Dswing.defaultlaf=javax.swing.plaf.nimbus.NimbusLookAndFeel -cp . Test_indexAtLocation OK OK indexAtLocation returns 1 for pane, but 2 is expected for[2] = java.awt.Rectangle[x=25,y=63,width=-7,height=22]! OK ---------------------------------------------------------------------------------------------------------------- OS: Solaris L&F: Nimbus used: spb-sapphire.russia.sun.com you may start /usr/local/bin/vncserver there to reproduce the problem visually
14-03-2011

EVALUATION The updated test doesn't show any problems on my machine, it prints "OK" three times. Please try the following test and let us know if the problem is persistent. import sun.awt.SunToolkit; import javax.swing.*; import java.awt.*; public class Test_indexAtLocation { static JTabbedPane tabbedPane; public static void main(String[] args) throws Exception { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { final Component components[] = {new Container(), new JButton(), new JCheckBox()}; final String names[] = {"1", "2", "3"}; tabbedPane = new JTabbedPane(); for (int j = 0; j < components.length; j++) { tabbedPane.addTab(names[j], components[j]); // Fill the set } final JFrame fr = new JFrame(); fr.getContentPane().add(tabbedPane); fr.pack(); fr.setVisible(true); } }); ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { for (int i = 0; i < tabbedPane.getTabCount(); i++) { Rectangle rr = tabbedPane.getBoundsAt(i); int index = tabbedPane.indexAtLocation( rr.x + rr.width / 2, rr.y + rr.height / 2); if (index != i) { System.out.println("indexAtLocation returns " + index + " for pane, but " + i + " is expected for[" + i + "] = " + rr + "!"); } System.out.println("OK"); } } }); } }
14-03-2011

EVALUATION Code sample rewritten to do everything on EDT. Problem still exists.
11-03-2011

EVALUATION The provided test is incorrect, JTabbedPane is created on the main thread and then its methods are also called outside EDT. Everything is possible with the test that has threading problems, closed as not a defect.
11-03-2011