This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a BufferedImage of an offscreen JButton (or other Component)

 
Michael Cooper
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create a Swing component that, in its paint() method, draws a possibly scaled version of JButtons and other Components. It would not be appropriate to physically place those Components inside the original Component because the layout managers would not do the type of "scaling" I am looking for - I would like the text/image inside to also be scaled.

What I am getting are empty gray boxes of the appropriate sizes. If I use JButtons I don't see the the rounded corners or the button text, and if I use a JPanel with a JLabel within I don't see the label's text. The problem appears to be with my use of the Component.createImage() function, but I can't figure out why.

Here's the basic code:



Thank you so much for any help!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic