Results 1 to 2 of 2
  1. #1
    Lacrim is offline Member
    Join Date
    Jul 2011
    Posts
    7
    Rep Power
    0

    Default 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.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default

    I start a thread which changes the Background of some labels, and buttons
    Respect Swing's single threaded rule. Lesson: Concurrency in Swing (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?
    You neglected to call the super implementation, which clears the background. Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    db

Similar Threads

  1. Filling with transparency
    By zirbinator in forum Java 2D
    Replies: 3
    Last Post: 02-09-2011, 02:36 AM
  2. Serializing BufferedImage with keeping transparency
    By Spitfire777 in forum Java 2D
    Replies: 2
    Last Post: 12-15-2010, 07:49 PM
  3. Alternating Transparency Based on Double Variable
    By YellowPainting in forum Java 2D
    Replies: 2
    Last Post: 11-05-2010, 08:59 PM
  4. ImageIcon Transparency
    By Lingerz in forum New To Java
    Replies: 2
    Last Post: 06-04-2010, 02:53 PM
  5. Setting an image's transparency?
    By aaroffl in forum AWT / Swing
    Replies: 1
    Last Post: 12-03-2008, 12:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •