This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Using fixed size across varible display resolutions  RSS feed

 
Sheriff
Posts: 6037
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a MDI GUI using JInternalFrames. Many of the GUI components have a "fixed" size and/or width. Here "fixed" can mean either never changes, or changes automatically, such as when rows are added to, or removed from a table. The point is, the user doesn't have to worry about sizing, as the software takes care of it automatically.
The problem is that a size which works well on screen resolution, doesn't always work on another. Is there any way to get the software to recognize the screen resolution and change my calculations based on that information?
Are there any recommended practices in situations like this, e.g. certsin settings, fonts, tricks, etc?
Thanks.

--Mark
 
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The java.awt.Toolkit class has getScreenResolution() and getScreenSize() methods. getScreenResolution() returns pixels-per-inch as an int, and getScreenSize() returns size of screen in pixels as a Dimension.

Recommended practice is not to use fixed sizes. It's much better to make use of layout managers, preferred sizes, and the pack() method. As you've found, fixed sizes have no guarantee of being portable between resolutions... or releases. Sun changed some sizing calculations between 1.3 and 1.4... and we had components disappear where developers had used null layout and fixed sizes. The component didn't think it could fit into the fixed size, so it didn't draw!
 
Mark Herschberg
Sheriff
Posts: 6037
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the input. Any recommendations for working with tables? Many of my JInternalFrame just hold tables, so there's no layout manager of significance.
--Mark
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you're doing with your tables, but I've always done something like this (setting the preferred viewport size... ). You can also set the preferred width of columns individually, and you could use FontMetrics to compute the size of strings...

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!