Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes problems with transparent background Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problems with transparent background" Watch "problems with transparent background" New topic
Author

problems with transparent background

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

when i set the background color of my JPanel using a JColorChooser to transparent(or even semi-transparent) i get all kinds of problems. otherwise no problems at all. no similar problems with foreground.


SCJP
Visit my download page
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167
    
    8

One would typically use setOpaque() or setContentAreaFilled() in case of a button to achieve transparency instead of the background color. So what kind of problems do you run into?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2152
    
    7
Having over 4000 postings you would think you would know how to ask a question with information necessary to answer the question.

I don't know what "I get all kinds of problems" means and I don't see a SSCCE.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

i solved the problem that led me to the bug by changing the way i faded an image(i was doing it ass-backwards). so now there is no reason to make the JPanel background transparent. however the bug remained. it basically crashes the program. too many things to describe. my battery ran out before i could try it but i am sure i fixed it by not letting the user do that. it must be that JPanel does not like having it's background color transparent. just add a line like this.

back = new Color(back.getRed(), back.getGreen(), back.getBlue(), 255);
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

i forgot to mention it doesn't throw an exception. it just causes the program to crash(buttons do the wrong thing as do menu items etc.). i don't think it is my code so i wonder if Oracle knows about this problem. as for an SSCCE, think about it. the SSCCE would be almost as long as my program and i am sure you don't want me posting a dozen classes. just thought i would alert people to this problem.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2152
    
    7
when i set the background color of my JPanel using a JColorChooser to transparent(or even semi-transparent) i get all kinds of problems


So, based on your description of the problem, then the SSCCE would be 1 line of code (in addition to the create of the frame):

panel.setBackground( new Color(...) ); //hardcode any transparent color here.

think about it ... i am sure you don't want me posting a dozen classes


I did think about. You haven't isolated the problem and you are asking us to guess based on a single line problem statement.

i don't think it is my code


How do you know? If your code is spread out over 12 classes, maybe you made a mistake.

Or, maybe you just don't understand the concept of how transparency works. Maybe Background With Transparency will help.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

here is how i fixed it

here is my JPanel

basically the JPanel wouldn't repaint correctly if the user made its background transparent
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

ps: i don't use an IDE. i jar from the command line. i have 18 class files now. i might jar the broken version for oracle if they want to see the problem but not for you.
write your own SSCCE if you don't believe me.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2152
    
    7
write your own SSCCE if you don't believe me.


You are quite amazing. How am I supposed to write a program that consists of 18 classes when I have no idea what you are really trying to do???

When I do write my own code and it works fine. That is why I asked for your SSCCE.

It is you that doesn't know/understand what you are doing. If you want help then it is your responsibility to write the SSCCE to show what you are doing.

If you think you need 18 class files to duplicate the problem, the chances are the problem is with your code.

This is not a problem that should be raised with Oracle. If you can't duplicate/isolate the problem, then it isn't a problem, it is just your coding.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

you are the one who is truly amazing. i told you over and over that it is not "my" problem but a problem with java. as i showed it is very easy to fix, but it should not occur in the first place. my program works fine. the user can no longer set the background of the JPanel to transparent.

since it is a paint program i have to let the user select a background color for the JPanel. i just made it so he cant select transparency
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2152
    
    7
You still have not posted a SSCCE. So stating it is a Java problem is completely unreasonable. Just because something doesn't work the way you expect it to does not make it a problem with Java. The painting mechanism for Swing is well documented.

Based on your verbal description, it is not a problem with Java. Java supports transparent backgrounds. Your code doesn't. Again, it appears to me you do not understand how the setOpaque() method works in Java. That is not Java's problem. That is your problem. I gave you a link that explains how this works. Apparently you choose to ignore it, or still don't understand it.

Your solution to not allow transparent backgrounds is a reasonable solution if it meets your requirements. But it is not the only solution.

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

well since the app has a feature to turn any color transparent, i guess it does meet my needs. at least for now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problems with transparent background
 
Similar Threads
SWT Composite setBackgroundImage() doesn't support transparency?
Background Color
2D animation/transparency question
reg applet
background?