Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

What event to catch when resizing a JFrame?

801431May 14 2010 — edited May 15 2010
Hello,
I added a JLabel to a JFrame's LayeredPane:
frame.getLayeredPane().add(label,100);
and putted the JLabel's text in the middle of the frame using this code:
label.setBounds(0, 0, frame.getWidth(), frame.getHeight());
Now I would like the JLabel to be centered in the JFrame automatically when the JFrame gets resized by the user. Is it possible?
I'm using the WindowStateListener:
frame.addWindowStateListener(new WindowStateListener() {
	public void windowStateChanged(WindowEvent e) {
		label.setBounds(0, 0, frame.getWidth(), frame.getHeight());
	}
});
but this only works when the JFrame is resized using the predefined window's button in the top-right corner.

I would like the JLabel to be resized when the user drags the borders too.

Thank you in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 12 2010
Added on May 14 2010
6 comments
507 views