Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Window resize event?

Tags:

java

swing

I'm writing a simple painting program using Java, and I want some method to be called whenever the JFrame component is resized. However I can't find any method like windowResizedListener or an event like windowResizedEvent. What can I do?!

like image 637
Ameer Jewdaki Avatar asked Feb 20 '10 19:02

Ameer Jewdaki


People also ask

What happen when window is resized?

The resize event fires when the document view (window) has been resized. This event is not cancelable and does not bubble. In some earlier browsers it was possible to register resize event handlers on any HTML element.

How do I capture a Windows resize event?

Answer: Use the addEventListener() Method You can simply use the addEventListener() method to register an event handler to listen for the browser window resize event, such as window. addEventListener('resize', ...) . The following example will display the current width and height of the browser window on resize.

Which event is triggered if the browser window is resized?

The onresize event occurs when the browser window has been resized.


2 Answers

Implement a ComponentAdapter with componentResized():

frame.addComponentListener(new ComponentAdapter() {     public void componentResized(ComponentEvent componentEvent) {         // do stuff     } }); 
like image 106
Yuval Adam Avatar answered Sep 23 '22 01:09

Yuval Adam


Overriding particular methods of ComponentAdapter is a convenient alternative to implementing all the methods of ComponentListener. Several examples seen here illustrate the "convenience for creating listener objects" mentioned in the API.

like image 32
trashgod Avatar answered Sep 21 '22 01:09

trashgod