This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problems with transparent background

 
Randall Twede
Ranch Hand
Posts: 4442
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Maneesh Godbole
Saloon Keeper
Posts: 11070
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rob Camick
Ranch Hand
Posts: 2600
9
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4442
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4442
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2600
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4442
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4442
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2600
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4442
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2600
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4442
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well since the app has a feature to turn any color transparent, i guess it does meet my needs. at least for now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic