Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing's components and Graphics2D.scale

 
Tomek Tajne
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 160
IntelliJ IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Tomek Tajne
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic