Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6967957

MToolkit : resizing a component in componentResized() is not propagated to content

    XMLWordPrintable

Details

    • b06
    • sparc
    • solaris_10

    Backports

      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();
                            }
                        });
                    }
                });
            }
        }

        Attachments

          Issue Links

            Activity

              People

                coffeys Sean Coffey
                apoddany Arnaud Poddany (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: