Results 1 to 11 of 11
Thread: Listener for JFrame size change
- 01-08-2008, 07:18 PM #1
Member
- Join Date
- Dec 2007
- Posts
- 13
- Rep Power
- 0
Listener for JFrame size change
Is there a listener that I can use that will listen for any size changes in the window/JFrame?
If the user resizes manually or the user maximizes/restores then I need to be able to get the new size, compare it to the old one and then move objects depending on the change.
Also, is there a way to know if a JFrame is maximized or not?
- 01-08-2008, 07:38 PM #2
Please run the code, you can continue thereafter ..Java Code:public class Main { public static void main(String[] args) { JFrame j = new JFrame(); j.setVisible(true); j.getContentPane().addHierarchyBoundsListener(new HierarchyBoundsListener(){ @Override public void ancestorMoved(HierarchyEvent e) { System.out.println(e); } @Override public void ancestorResized(HierarchyEvent e) { System.out.println(e); } }); } }dont worry newbie, we got you covered.
- 01-08-2008, 07:45 PM #3
Please see javadocs for Frame.getExtendedState() for Maximized thing ..
dont worry newbie, we got you covered.
- 01-08-2008, 07:51 PM #4
Member
- Join Date
- Dec 2007
- Posts
- 13
- Rep Power
- 0
Thanks, I'll give that a try.
Another thing, currently I'm doing a while loop to get an object to move say...100 pixels.
However (logicly) it does it instantly since I didn't tell it to wait a few milliseconds between moving a pixel.
I tried using the wait(); method but it gives the IllegalMonitorStateException.
Any ideas?
- 01-08-2008, 07:58 PM #5
Java Code:try { Thread.sleep(100); } catch (InterruptedException e1) {}dont worry newbie, we got you covered.
- 01-08-2008, 08:23 PM #6
Member
- Join Date
- Dec 2007
- Posts
- 13
- Rep Power
- 0
I got an odd problem with that one.
Instead of moving the image one pixel, wait & show the change, and then repeat it just seems to wait until the distance has been covered and then it shows the new position, still doing it instantly but with a delay before it (the amount of pixels * msec)
Using a println() I was able to find out that it does do the sleep part correctly but it doesnt seem to update the image itself until it reaches its end.
- 01-08-2008, 08:57 PM #7
If you need precision timing with your animation .. adopt double buffering and control the display with System time ..
dont worry newbie, we got you covered.
- 01-08-2008, 09:01 PM #8
Member
- Join Date
- Dec 2007
- Posts
- 13
- Rep Power
- 0
No I dont need it to be precise, I just need to be able to move a JPanel somewhat smoothly.
The sleep loop works fine itslef but the JPanel isnt being moved while the loop is going, it only moves before and after the loop, it goes from x=0 to x=100 instead of x=1,x=2,x=3,x=4,x=5,x=6 and then moving.
I tried panel.repaint(), frame.repaint(), validate() and a bunch of other stuff but it still doesnt work.
I also tried creating a blank jFrame/class with just a JFrame and a JPanel to move but it had the same result.
- 01-08-2008, 09:19 PM #9
* Painting in AWT and Swing
* Java Game Development - force the repaint of a JPanel
Hoping you can get something from there ..dont worry newbie, we got you covered.
- 01-08-2008, 09:28 PM #10
Member
- Join Date
- Dec 2007
- Posts
- 13
- Rep Power
- 0
I tried this.paint(getGraphics()); and that seems to have done it :D
Last edited by Thez; 01-08-2008 at 09:56 PM.
- 02-14-2008, 03:10 PM #11
Member
- Join Date
- Feb 2008
- Posts
- 1
- Rep Power
- 0
Similar Threads
-
add an undo listener to a Jtable
By christina in forum Advanced JavaReplies: 12Last Post: 01-29-2009, 07:47 AM -
Tree with Listener not working when added to ScrollPane
By praveen.kb in forum AWT / SwingReplies: 2Last Post: 01-09-2008, 07:06 AM -
Listener for SWT event
By Java Tip in forum Java TipReplies: 0Last Post: 01-08-2008, 09:04 AM -
Listener collision on game
By cachi in forum Java AppletsReplies: 1Last Post: 08-07-2007, 07:48 AM -
Adding listener to non-Java object?
By cruxblack in forum Advanced JavaReplies: 5Last Post: 07-30-2007, 02:19 AM


LinkBack URL
About LinkBacks

Bookmarks