Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: AWT Frame with constant height-width ratio



> I tried the following code...

oops, forgot to paste the code:

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class Test {
    
    public static void main(String[] args) {
        final JFrame mediaPopup = new JFrame();
                 mediaPopup.addComponentListener( new ComponentAdapter()
{
                     private int RESIZE_SLEEP_DELAY = 10;
                     private float aspect = 1.0f;
                     private boolean isInitialized = false;
                     public void componentResized( final ComponentEvent
e ) {
                         if( ! isInitialized ) {
                             Dimension d = mediaPopup.getSize();
                             aspect = ((float)d.width) /
((float)d.height);
                             isInitialized = true;
                         }

                         SwingUtilities.invokeLater(new Runnable() {
                             public void run() {
                                 Rectangle r =
e.getComponent().getBounds();
                                 mediaPopup.setSize( (int) (r.height *
aspect), 
                                     r.height );
                             }
                         });
                     }
                 } );

        mediaPopup.pack();
        mediaPopup.show();
    }
}
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.