United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-5037709 : JTabbedPane problems with scrolling to selected tab

Details
Type:
Bug
Submit Date:
2004-04-26
Status:
Open
Updated Date:
2013-05-17
Project Name:
JDK
Resolved Date:
Component:
client-libs
OS:
windows_2000
Sub-Component:
javax.swing
CPU:
x86
Priority:
P4
Resolution:
Unresolved
Affected Versions:
1.4.2
Targeted Versions:

Related Reports

Sub Tasks

Description

Name: gm110360			Date: 04/26/2004


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

FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
It appears that JTabbedPane won't auto scroll to a tab which was just added.
Autoscrolling to a tab which was previously added sometimes works, though.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the attached program: javac TabbedPaneTest.java
Run the attached program: java TabbedPaneTest
You will see a window with one tab. The tab is labeled '1'
and contains a panel title '1' with three buttons.

Click the button labeled Create. A new tab, 2, is added
and selected, decorated similarly.

Click the Create button in the selected tab until 6 tabs
are present; the last tab, 6, is now selected.

Click the Create button again. Tab 7 has been selected but
is not visible; that is, the tab itself is not visible; the
contents or component associated with the tab _is_ visible.
>> THIS IS THE PROBLEM! <<

Click Create until Tab 10 is selected. Notice how none of
the selected tabs is made visible even though the associated
compent is! >> THIS IS THE PROBLEM! <<

Click the button labeled '?'. The text changes from '?' to
'7'. This button, when clicked in any panel, changes its
text to a number. This number will be the tab selected when
the Select button is clicked.

Click the select button now. Tab 7 is now selected and whoa,
it was scrolled too as well. >> I WONDER WHY IT WORKS NOW? <<

Click create until the contents of tab 20 are displayed. Of
course, the tab itself is not visible. Click the '?' button.
The text changes to '17'.

Notice that the currently visible tabs are 2 through 7. Click
the Select button. Notice that
1) Contents of tab 17 displayed.
2) Tab 17 not visible.
3) The tabs, however, did scroll; now visible are tabs 6 through
   10 and part of tab 5. >> THIS IS ALSO THE PROBLEM. <<

Click the button labeled '?'. The text changes to '17'. Click
the Select button. No change.

Now click the left arrow button until tab 1 is displayed. Select
tab 1 by clicking the tab labeled '1'. Click the '?' button. The
text changes to 17. Click the Select button. >> NOW IT WORKS? <<

Something pretty funky is going on.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected that any time a tab was selected, the tab itself as well as the
contents of the tab would be visible.
ACTUAL -
A tab which was just added and then selected was not made visible if scrolling
was required, though the contents of the tab were displayed.

REPRODUCIBILITY :
This bug can be reproduced always.

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

public class TabbedPaneTest extends JTabbedPane {
    int counter = 1;

    public TabbedPaneTest() {
        super(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    }

    public void createTab() {
        addTab(Integer.toString( counter ),
                    createDefaultPanel( counter ) );
        setSelectedIndex(counter - 1);
        counter++;
    }

    private JPanel createDefaultPanel (int index) {
        JPanel defaultPanel = new JPanel ();
        defaultPanel.setBorder( BorderFactory.createTitledBorder(
                BorderFactory.createLoweredBevelBorder(),
                                Integer.toString(index) ) );

        JButton create = new JButton( "Create" );
        defaultPanel.add( create );
        create.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                createTab();
            }
        });

        JButton select = new JButton( "Select" );
        defaultPanel.add( select );
        select.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if ( counter > 5 )
                    setSelectedIndex( counter - 5 );
            }
        });

        JButton query = new JButton( "?" );
        defaultPanel.add( query );
        query.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JButton button = (JButton) e.getSource();
                button.setText( Integer.toString( counter - 4 ) );
            }
        });

        return defaultPanel;
    }

    public static void main ( String args [] ) {
        JFrame frame = new JFrame ();
        TabbedPaneTest tpt = new TabbedPaneTest ();
        frame.getContentPane().add(tpt);
        frame.setSize(200, 200);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        tpt.createTab();
    }
}

---------- END SOURCE ----------
(Incident Review ID: 198832) 
======================================================================

                                    

Comments
EVALUATION



Name: drR10255			Date: 05/06/2004

The problem (or problems) exists.



======================================================================
                                     
2004-09-25



Hardware and Software, Engineered to Work Together