GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes Monitoring window resizes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Monitoring window resizes" Watch "Monitoring window resizes" New topic
Author

Monitoring window resizes

Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Okay this is a really really stupid question but for some reason it's escaping me. I have a JDesktopPane with two JInternalFrames, I want to keep them at a certain ratio, like for example each taking up half the screen. Setting that up is easy to begin with but how do I know when the main JFrame has been resized so that I can resize the internal frames to be half the new size?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

There are no stupid questions.
Implement a ComponentListener, add it to the JFrame using addCOmponentListener(). The ComponentListener's componentResized() method will be called when the JFrame has been resized.


[Jess in Action][AskingGoodQuestions]
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Righto, then I'm safe to get the size of the thing and resize my internal frames just as I do during initalization? I mean it's not going to be called during the resize or anything like that so I don't have to worry about whether or not it's going to return the correct size and what not.
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Actually I'd also like to post a couple follow up questions that are somewhat related, no sense in creating a new thread.
First of all, the point of doing this was so that I could 'dock' these frames so that one frame takes up the left half and another the right half. I also want to add in functionality so that if the user resizes these windows that if they have chosen to have the windows scale with the frame that it will maintain it's current ratio. i.e. if it's half it will still be half. That's simple enough if I know that I want to it to be half the screen, however, if the user changes the size to something different by resizing the internal frame then I no longer want it to be half, I want it to scale in size and position based upon what it is now.
So my question is how do I go about implementing this? I need some way of checking to see what the internal frame's sizes are before resizing so I can maintain the same ratio. Is there an easy way of doing this? Do I have to add a component listener on every internal frame and when they are resized record what their size and location are and then use that when I determine positions when my main frame is resized or what?
The other thing is I have an ImageDisplay widget that I created, it's for viewing, zooming, and otherwise manipulating an image. One of the things I want is for the scroll wheel to zoom in and out of the image. I've successfully implemented this feature, however, I've not found a good way of having it work all the time. In other words it only works when the ImageDisplay has focus, I want it to always work and for it to do so on the last ImageDisplay that had focus (in case there is more than one, which is a possibility, though I doubt it).
Thanks.
[ January 18, 2004: Message edited by: Ken Blair ]
 
GeeCON Prague 2014
 
subject: Monitoring window resizes