• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problems with transparent background

 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 3324
32
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic