• Post Reply Bookmark Topic Watch Topic
  • New Topic

JFrame Resizing  RSS feed

 
Fabricio Sanchez
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I'm trying to override the paint method on a JFrame so that the frame is blank as it is resized and when the resize is finished it gets back to normal and redraws.


Overriding ComponentListesner.componentResized(ComponentEvent e) only tells me when the JFrame resize is completed. Ideally I want to disable painting as the JFrame is resizing.
So that's no good


Also tried overriding:
MouseListener.mousePressed (to record the jframe's width and height)
MouseMotionListener.mouseDragged( to compare current jframe size with recorded ones above, and if so stop paint() on JFrame)
MouseListener.mouseReleased( to reset the paint() method back to normal and repaint the JFrame)
However, this doesn't work as when resizing the JFrame no MouseEvents are fired

Another way I found was to create a separate Thread that would report on the size of the JFrame at various intervals. This is not ideal, as I don't wan't to waste resources like, I don't want a separate thread for something that will not be used that much.

Does anyone know a better way of accomplishing this?

Thank you,

Fabricio
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Define a boolean say isDragged.
Add mouse listener for mouse clicked and mouse released.
Toggle the boolean on click/release
In your overridden paint, check the boolean and decided to repaint or not.
 
Fabricio Sanchez
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Maneesh,

That is the second thing I tried (see original post), the only problem is that no MouseEvents are fired on the resize border around the JFrame, so nothing gets picked up as the JFrame is resizing.
(If I was interested in resizing a component within it, it would be fine as MouseEvent are fired within components)

Any other ideas?

Fabricio
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Works for me.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Overriding ComponentListesner.componentResized(ComponentEvent e) only tells me when the JFrame resize is completed

add the listener to the contentPane instead, and it will fire continuously during resize
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:
add the listener to the contentPane instead, and it will fire continuously during resize


Awesome
 
Fabricio Sanchez
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Michael.

That works. Although strangely, when I'm resizing the JFrame (making it smaller) it doesn't fire a ComponentListesner.componentResized event immediately. When I make the JFrame bigger it fires it straight away.

It's a shame there isn't a standard isResizing (or startResize, endResize) event that can be caught directly from the JFrame.

Thanks again.

Fabricio
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!