How Do I Write Listeners for Resizing or Maximizing a Window?

K

kvnsmnsn

I'm familiar enough with Java that I can create a <JPanel> object and
build listeners that execute when the user clicks a mouse in it, or
drags a mouse across it, or moves a mouse off of it. My question now
is how do I write listeners that execute when the user resizes the
window or maximizes the window? I've looked through the classes at
"java.sun.com/j2se/1.5.0/docs/api/index.html", but haven't found any-
thing that looks like it would work. Could someone give me some
pointers on this? Any information would be greatly appreciated.

---Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
 
J

Joan

I'm familiar enough with Java that I can create a <JPanel>
object and
build listeners that execute when the user clicks a mouse in
it, or
drags a mouse across it, or moves a mouse off of it. My
question now
is how do I write listeners that execute when the user resizes
the
window or maximizes the window? I've looked through the
classes at
"java.sun.com/j2se/1.5.0/docs/api/index.html", but haven't
found any-
thing that looks like it would work. Could someone give me
some
pointers on this? Any information would be greatly
appreciated.
// consider these program fragments

class xxx implements ComponentListener {}
yyy.addComponentListener(this);
public void componentMoved(ComponentEvent e) {}
public void componentResized(ComponentEvent e) {}
 
O

Oliver Wong

I'm familiar enough with Java that I can create a <JPanel> object and
build listeners that execute when the user clicks a mouse in it, or
drags a mouse across it, or moves a mouse off of it. My question now
is how do I write listeners that execute when the user resizes the
window or maximizes the window? I've looked through the classes at
"java.sun.com/j2se/1.5.0/docs/api/index.html", but haven't found any-
thing that looks like it would work. Could someone give me some
pointers on this? Any information would be greatly appreciated.

Haven't actually tested this with code, but it seems that resizing and
maximizing would typically require mouse clicks. Have you thought about
listening for mouse clicks and then checking if the size of the window with
previously known sizes?

You can do something similar to keyboard shortcuts which resize/maximize
the window.

- Oliver
 
E

Eric Sosman

I'm familiar enough with Java that I can create a <JPanel> object and
build listeners that execute when the user clicks a mouse in it, or
drags a mouse across it, or moves a mouse off of it. My question now
is how do I write listeners that execute when the user resizes the
window or maximizes the window? I've looked through the classes at
"java.sun.com/j2se/1.5.0/docs/api/index.html", but haven't found any-
thing that looks like it would work. Could someone give me some
pointers on this? Any information would be greatly appreciated.

theComponent.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent evt) {
// your code here ...
}
});
 
R

Roedy Green

Haven't actually tested this with code, but it seems that resizing and
maximizing would typically require mouse clicks. Have you thought about
listening for mouse clicks and then checking if the size of the window with
previously known sizes?

those mouse clicks are massaged into other events.
 
K

kvnsmnsn

Joan wrote:

=class xxx implements ComponentListener {}
=yyy.addComponentListener(this);
=public void componentMoved(ComponentEvent e) {}
= public void componentResized(ComponentEvent e) {}

Thanks, Joan! This worked just fine.

---Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top