Solved

JFrame listen to a resize event?

Posted on 2003-10-28
4
773 Views
Last Modified: 2013-11-23
Hello,

 Every time I drag and expand my JFrame it does not seem to respond to the events I used. Is there a way I can listen for the resize event of a JFrame and check to see if both the height and width are the same. If they are not force a automatic adjustment to make the JFrame have both the same height and width using the smaller of the two to set the other? A simple example would be great. Thank you.
0
Comment
Question by:entercite
4 Comments
 
LVL 1

Accepted Solution

by:
nex1999 earned 25 total points
ID: 9637243
try adding a Component Listener:

        this.addComponentListener(new ComponentAdapter()
        {
              public void componentResized(ComponentEvent event)
              {
                   if(getWidth() < getHeight() )
            setSize(getWidth(), getWidth() );
          else
                      setSize(getHeight(), getHeight() );
                   repaint();
              }
          });
0
 
LVL 2

Assisted Solution

by:Tols
Tols earned 25 total points
ID: 9640108
If You want to see components resizing during Frame resize:

this.getToolkit().setDynamicLayout(true);

Just a tip. :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Requested array size exceeds VM limit 3 84
egit plugin on eclipse 8 33
Syntax Error 2 44
xampp tool 12 24
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now