Results 1 to 5 of 5
  1. #1
    sowilo is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default weird insets change in JFrame subclass

    Hi,
    I have a strange problem concerning one of my classes that extends JFrame.

    The application using it starts with a dialog with a listener registered to it that builds and displays a game window (class GameFrame; the class in question) whenever the user chooses OK in the dialog. When this window is closed it is disposed (using DISPOSE_ON_CLOSE as closing operation) and another listener re-enables the dialog by making it visible again. Then the play can start again.

    GameFrame objects provide an init routine that takes care of layout and sizing. The latter duty causes problems: The frame contains a component I want to size depending on the maximum available (screen) space. Therefor, I first pack the (empty) GameFrame to get it's insets through a call of JFrame.getInsets() and then calculate the available space on the basis of the insets and Toolkit.getDefaultToolkit().getScreenSize(). Since some of my calculations were faulty I checked the insets I used and I noticed that the first window created by the dialog's listener has insets [top=25, left=5, bottom=5, right=5] and any following window created the same way (without restarting the application) has insets [top=24, left=5, bottom=6, right=6].

    I have no idea what the reason is since I definitely create a new GameFrame object each time. Any suggestions?

    Regards.
    Last edited by sowilo; 11-15-2009 at 10:51 PM.

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    The frame contains a component I want to size depending on the maximum available (screen) space
    Java Code:
    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    Now any component added to the frame will automatically take up all the available space.

  3. #3
    sowilo is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default

    thanks for your answer but I don't want do maximize the component, I just want to calculate it's size depending on the available space. (the component has to be squarish).
    Last edited by sowilo; 11-16-2009 at 01:20 AM.

  4. #4
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    5

    Default

    The obvious stupid suggestion is to cure the symptom, not the disease.
    On start-up create and discard a window. Then all subsequent windows
    will have the not-the-first window size.

  5. #5
    sowilo is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default

    Ok, sizing is no longer a problem. I found a way to accomplish it without using the insets directly.
    Anyways, I still wondered what causes this ugly bug and did some tests: behold, it is not my fault. JFrame.setVisisble() called the first time triggers the insets change ...

    Regards.

Similar Threads

  1. JFrame window doesnt change background color
    By Addez in forum New To Java
    Replies: 7
    Last Post: 11-07-2009, 09:38 PM
  2. Change the shape of JFrame
    By kiki2009 in forum New To Java
    Replies: 4
    Last Post: 07-09-2009, 01:47 PM
  3. Weird Error?
    By sciguy77 in forum New To Java
    Replies: 4
    Last Post: 01-20-2009, 02:32 AM
  4. [SOLVED] How to set insets for JComboBox.......?
    By prabhurangan in forum AWT / Swing
    Replies: 3
    Last Post: 07-01-2008, 06:25 AM
  5. Listener for JFrame size change
    By Thez in forum AWT / Swing
    Replies: 10
    Last Post: 02-14-2008, 03:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •