This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Swing's components and Graphics2D.scale Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Swing Watch "Swing New topic
Author

Swing's components and Graphics2D.scale

Tomek Tajne
Greenhorn

Joined: Oct 05, 2011
Posts: 2
Hello,

I have image and Swing components in my panel and I'm trying to resizing it by using Graphics2D.scale(int, int), but Swing's component aren't looking properly after that.
See what's happen with JButton and JLabel after using Graphics2D.scale.
How can I fix it?

Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 157

Why don't you just call setPreferredSize() on your components? That is the more 'correct' way of doing it. Generally you shouldn't be messing with the way in which Swing components are painted.


"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." - George Bernard Shaw
Tomek Tajne
Greenhorn

Joined: Oct 05, 2011
Posts: 2
Riaan Nel wrote:Why don't you just call setPreferredSize() on your components? That is the more 'correct' way of doing it. Generally you shouldn't be messing with the way in which Swing components are painted.

I'm trying to resize view of whale panel with a big image and many Swing Components. There is no image in the code I've pasted above, but there is a rectangle instead.
I need buttons with zoom in/zoom out options, and I though that using Graphics2D.scale would be the best option, because Image.getScaledInstance takes too much time
Do you know how to fix this code?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Swing's components and Graphics2D.scale
 
Similar Threads
Graphics Graphics Graphics - Where are my circles?
Dialogs windows not displaying properly
Alignment of JTextArea in OverlayLayout
animation not animating...
How to build focus rectangle