File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Aspect ratio of Components

 
Andrew Cho
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all,

Does anyone know of a good way to keep a certain aspect ratio of a Component, when the Container is resized?

Much appreciated,
Andrew
 
Walter Gabrielsen Iii
Ranch Hand
Posts: 158
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would take the longest side of the original component and try to fit it inside the shortest side of the new, resized, area (you need to take a measurement of your original component's size first, before it is resized.).

Example:

(shortest side of new) / (longest side of old)
= multiplier for both of the component's dimensions.


Or, as applied, how much to scale a 32x32 icon to fill a 640x480 screen?
480 (the shortest size of the new space)
480/32 = 15
(so multiply each side by 15)
15*32 = 480, or 480x480 -- it fits as much as possible inside the shortest side of my new 640x480 space, while keeping the original size's aspect ratio.
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would start by separating the responsibilities. A code example explains this in less words than I would take to describe it.Play around with the parameters passed to the ProportionalPanel's constructor and the limit of the loop index and see the difference.

Note that for practical usage, the layout in which the proportional panel is housed plays a role.
 
Andrew Cho
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Darryl,
Thanks for your input, however, I'm not sure that I understand what this code does. It seems as if it just resizes the JLabels normally...
 
Paul Clapham
Sheriff
Pie
Posts: 20187
26
MySQL Database
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes... what you want is for the layout manager to resize the labels automatically as the container is resized, correct?

So therefore you want a layout manager which can preserve the aspect ratio of your labels.

None of the built-in layout managers do that, at least not that I know of. So your choices are two: search the web for layout managers which do what you want, or write a layout manager which does what you want.
 
Andrew Cho
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone,
I just went ahead and wrote my own.
Took a while since it was my first, but well worth it as it does exactly what I want.

Thanks again,
Andrew
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic