United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6967957 MToolkit : resizing a component in componentResized() is not propagated to content
JDK-6967957 : MToolkit : resizing a component in componentResized() is not propagated to content

Details
Type:
Bug
Submit Date:
2010-07-09
Status:
Resolved
Updated Date:
2011-01-12
Project Name:
JDK
Resolved Date:
2010-10-05
Component:
client-libs
OS:
solaris_10
Sub-Component:
java.awt
CPU:
sparc
Priority:
P2
Resolution:
Fixed
Affected Versions:
6u20
Fixed Versions:
6u22-rev (b06)

Related Reports
Backport:
Backport:
Backport:
Relates:

Sub Tasks

Description
Compile and execute the following testcase with MToolkit.

- Click on "Open Dialog" button
A new JDialog (500x500) will appear with a "New Button" inside
- Resize the JDialog to a smaller size
The "New Button" does not return to the default preferred size (500x500) of the JDialog.

This happens only with MToolkit. Works with XToolkit.

% cat Test.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Test {

    public static void main(String[] args) {

        final Frame f = new Frame();
        f.setLayout(new BorderLayout());
        f.setBounds(0, 0, 500, 110);
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent ev) {
                System.exit(0);
            }
        });

        JButton b = new JButton("Open Dialog");
        f.add(b, BorderLayout.NORTH);
        f.setVisible(true);

        b.addActionListener( new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                JDialog jd = new JDialog( f );
                JButton jb = new JButton("New Button");
                jb.setPreferredSize( new Dimension (500,500) );
                jb.setMinimumSize(jb.getPreferredSize());
                jd.getContentPane().add( jb );
                jd.validate();
                jd.setVisible( true );
                final Dimension prefSize = jd.getPreferredSize();

                jd.addComponentListener( new ComponentAdapter()  {
                    public void componentResized( ComponentEvent e )  {
                        Dimension redimSize = e.getComponent().getSize();
                        Dimension newSize = new Dimension( redimSize );
                        System.out.println( "Preferred Size: "+prefSize.width+" "+ prefSize.height +
                                                    " RedimSize: "+redimSize.width+" "+redimSize.height);
                         if ( redimSize.width < prefSize.width )
                             newSize.width = prefSize.width;
                         if ( redimSize.height < prefSize.height )
                             newSize.height = prefSize.height;
                         e.getComponent().setSize( newSize );
                        // a possible workaround : force component refresh with validate()
                        // e.getComponent().validate();
                    }
                });
            }
        });
    }
}

                                    

Comments
WORK AROUND

use XToolkit
or 
force component refresh with validate() in componentResized()
                                     
2010-07-09
EVALUATION

Fix for 5025858 seems to have caused this regression.
                                     
2010-08-25



Hardware and Software, Engineered to Work Together