• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

JFrame Resizing

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Works for me.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic