Results 1 to 2 of 2
Thread: Transparency problem
- 07-27-2011, 12:55 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 7
- Rep Power
- 0
Transparency problem
Hi guys
I have an applet with overriden JButton to become an Oval. I use there an BufferedImage to make all the space to fill the rectange transparent. Therefore I don't clear the Graphics.
On the start everything is right and clear, but secondly I start a thread which changes the Background of some labels, and buttons. And here is the problem. The space between the oval and the rectange (from the BufferedImage) isn't clear now. It has some colors and shapes from other cotrols, why? How can I make this work?
Here is the code:
Java Code:protected void paintComponent(Graphics g) { BufferedImage of = new BufferedImage(getWidth(),getHeight(),BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D)of.getGraphics(); RenderingHints hints = new RenderingHints( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); g2.setRenderingHints(hints); g2.setColor(getBackground()); g2.fillOval(0,0,getWidth(),getHeight()); //g.clearRect(0, 0, getWidth(), getHeight()); g.drawImage(of,0,0,null); }Last edited by Lacrim; 07-27-2011 at 01:07 PM.
- 07-27-2011, 01:34 PM #2
Respect Swing's single threaded rule. Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)I start a thread which changes the Background of some labels, and buttons
You neglected to call the super implementation, which clears the background. Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)The space between the oval and the rectange (from the BufferedImage) isn't clear now. It has some colors and shapes from other cotrols, why? How can I make this work?
db
Similar Threads
-
Filling with transparency
By zirbinator in forum Java 2DReplies: 3Last Post: 02-09-2011, 02:36 AM -
Serializing BufferedImage with keeping transparency
By Spitfire777 in forum Java 2DReplies: 2Last Post: 12-15-2010, 07:49 PM -
Alternating Transparency Based on Double Variable
By YellowPainting in forum Java 2DReplies: 2Last Post: 11-05-2010, 08:59 PM -
ImageIcon Transparency
By Lingerz in forum New To JavaReplies: 2Last Post: 06-04-2010, 02:53 PM -
Setting an image's transparency?
By aaroffl in forum AWT / SwingReplies: 1Last Post: 12-03-2008, 12:01 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks