Trapping the JFrame resize event
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   John_Preston
Posted On:   Friday, April 12, 2002 08:01 AM

I have a JFrame inside which I have a JLabel image (that takes some time to create). I want to know how to trap the resize events of the JFrame so that I can rebuild the image when the rezing of the JFrame is finished (mouse released). I can't use ComponentListener events because these occur multiple times during the reszing and there is no indication that the mouse button has been released. Also AWTevents do not pass on the mouse pressed or mouse released events (they seem to be consumed by the JFrame). Any thoughts on how I can tell that the mouse has been released and thus initiate a image remake. The image is built by another server and can take a whil   More>>

I have a JFrame inside which I have a JLabel image
(that takes some time to create). I want to know how to trap the resize events of the JFrame so that I can rebuild the image when the rezing of the JFrame is finished (mouse released).


I can't use ComponentListener events because these
occur multiple times during the reszing and there
is no indication that the mouse button has been
released.


Also AWTevents do not pass on the mouse pressed
or mouse released events (they seem to
be consumed by the JFrame).


Any thoughts on how I can tell that the mouse has been released and thus initiate a image remake. The image is built by another server and can take a while, thus I cannot fire off multiple requests as with the componentresized events.

   <<Less

Re: Trapping the JFrame resize event

Posted By:   Anonymous  
Posted On:   Monday, April 15, 2002 06:11 AM

I used a ComponentListener on the Frame.
And it works for me, the resizing event is called only once,
when the mouse is released.
(using JDK 1.3.1_03 on WinNT)

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

/*
*
*/
public class test extends JFrame {

// constructor
public test() {
super("example");
createGUI();
pack();
show();
addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
System.out.println("resized call");
}
});

}

// create the Graphical Interface
public void createGUI() {

JLabel label =new JLabel("label");
getContentPane().add(label,"Center");

}

// main method
public static void main(String [] args ) {
new test();
}
}
About | Sitemap | Contact