• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JFrame size and location problems

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have a swing app that uses JFrame as it's main window. It contains a JPanel with several JTabbedPaneS and lots of components. The app reads a ResourceBundle containing the last size and location. During the WindowEvent.WINDOW_CLOSING event, I want to poll the JFrame's current size and location, then save it in the ResourceBundle file.

After I load up all the tabs, panels, components etc., and invoke the JFrame.pack() method, the JFrame size is not what was recorded in the properties file, which is as expected. But if I re-poll the window size and position later when the app is closing, the size is different than originally reported even if I don't resize the main window.


ResourceBundle at app start:


Main window init:


Window close method:


I clearly don't understand something about the behavior of pack() or the Swing framework.

I'm unsure of how the JFrame.pack() figures out its padding so I can adjust for it at app close. Also I don't know why the getBounds() method would report two different sets of values - even if no change has been made to that JFrame.

Any advice would be helpful.

Thanks
-bob
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> But if I re-poll the window size and position later when the app is closing, the size is different than originally reported even if I don't resize the main window.

Post your SSCCE that demonstrates this behaviour.
 
Bob Little
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Camick wrote:> But if I re-poll the window size and position later when the app is closing, the size is different than originally reported even if I don't resize the main window.

Post your SSCCE that demonstrates this behaviour.



Thanks for the reply Rob.
I haven't been able to reproduce this on a smaller scale to 100% satisfaction. But I've at least seen something that gave me a clue.

When the following code is compiled and run, the behavior is as I'm expecting. If the call to setBounds is commented out and the code recompiled and rerun, the window width and height after pack differs from when windowClosing is invoked. This tells me that I've created the behavior I've described through some incorrect combinations of object construction and size setting methods (or lack thereof). I'm thinking that as a result, Swing is left to calculate the size and location based on some defaults, which may or may not be what I am expecting.

In my full application, I was pretty sure I had called setBounds on all the components I'm using, but I cannot be sure right now.
Being that I have a ton of components spread out over several tabs, its probable I haven't done something right somewhere.


So this topic can be considered solved. Cause: Loose Nut Behind Keyboard.
-bob

 
reply
    Bookmark Topic Watch Topic
  • New Topic