United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-7171632 : JToolbar with JTextField does not layout its components correctly using Nimbus

Details
Type:
Bug
Submit Date:
2012-05-24
Status:
Open
Updated Date:
2014-03-28
Project Name:
JDK
Resolved Date:
Component:
client-libs
OS:
linux
Sub-Component:
javax.swing
CPU:
x86
Priority:
P4
Resolution:
Unresolved
Affected Versions:
7
Targeted Versions:
tbd_major

Related Reports

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) 64-Bit Server VM (build 21.1-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
RHEL 5 (Linux 2.6.18-262.el5 x86_64 GNU/Linux)

A DESCRIPTION OF THE PROBLEM :
When using the Nimbus Look And Feel, the JButton in a JToolBar setup as follows should be visible:
JToolBar
       JTextField (with columns = 20)
       Horizontal Glue
       JButton

However, the JButton is not visible as the layout manager for the tool bar does not correctly account for the width of the text field.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the test case using the Nimbus Look And Feel.
Execute the test case using the Metal Look And Feel.
Compare the results. The button is visible in Metal and not visible in Nimbus.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The JButton should be inside the viewable portion of the JToolBar.
ACTUAL -
The JButton is not visible within the viewable portion of the JToolBar.

REPRODUCIBILITY :
This bug can be reproduced always.

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

public class TextFieldTest extends JFrame
{
    public TextFieldTest()
    {
        // Create the text field
        JTextField textField = new JTextField( 20 )
        {
            @Override
            public Dimension getMaximumSize()
            {
                return super.getPreferredSize();
            }
        };
        
        // Create the tool bar
        JToolBar toolBar = new JToolBar();
        toolBar.add( textField );
        toolBar.add( Box.createHorizontalGlue() );
        toolBar.add( new JButton( "Button" ) );
        
        // Layout the frame
        getContentPane().setLayout( new BorderLayout() );
        getContentPane().add( toolBar, BorderLayout.NORTH );
        setPreferredSize( new Dimension( 800, 600 ) );
        pack();
    }
    
    
    public static void main( String[] args )
    {
        SwingUtilities.invokeLater( new Runnable()
        {
            public void run()
            {
                TextFieldTest test = new TextFieldTest();
                test.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
                test.setVisible( true );
            }
        } );
    }
}

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

                                    

Comments



Hardware and Software, Engineered to Work Together