JDK-6967957 : MToolkit : resizing a component in componentResized() is not propagated to content
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6u20
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_10
  • CPU: sparc
  • Submitted: 2010-07-09
  • Updated: 2011-01-12
  • Resolved: 2010-10-05
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 6
6u22-rev b06Fixed
Related Reports
Relates :  
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
EVALUATION Fix for 5025858 seems to have caused this regression.
25-08-2010

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