This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

JPanel Transparent does not work with setO

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I try to make my 2nd JPanel on my 1st JPanel transperant. Anyone sees a problem with this?



Aim is to place the tablesOld on top of tables, with transparence. Thanks for your hints.
 
Sheriff
Posts: 21817
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setOpaque(true) makes the panel non-transparent. Use setOpaque(false) to make it transparent. See also http://en.wikipedia.org/wiki/Opacity_(optics)
 
Knut Nilson
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried true and false, since I did not get any error message, but also no desired result. Is there may be another way I can check, why it is not working?
 
Saloon Keeper
Posts: 10785
231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setOpaque() is actually a misnomer. They should have called it setOpaqueGuaranteed() or something, but of course that's more wordy.

Swing needs to know if components guarantee they are opaque. Opaque in this context means that they paint every pixel within their bounds. If a component can guarantee that it will paint every pixel within its bounds, then Swing doesn't have to go through the trouble of painting other stuff beneath it.

If you want a component that's partially transparent, you will have to make sure isOpaque() returns false, so Swing knows it has to take special precautions. In JPanel, you can let isOpaque() return whatever value you set using setOpaque(). However, this is only half the issue. You still actually have to make parts transparent. You can only do this by providing your own paintComponent() method, and instead of calling super.paintComponent(g), you do all the painting yourself (and don't paint the parts you want to be transparent).
 
Knut Nilson
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replay, but I have trouble turing this into a working code. Can you may provide some additional hint for. May I do also two things at a time, which cancel eachother out.

 
Stephan van Hulst
Saloon Keeper
Posts: 10785
231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us your paintComponent() method, and describe what you want your component to look like. Posting your DashboardChart class would be helpful too.
 
Knut Nilson
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you think I have a customized version of paintComponent(), as far as I thought I have not specified anything special
As desired, please see here the DashboardChart section, may it gives you a hint:
public abstract class DashboardChart extends JPanel implements Observer


How it should look like: I have one Panel (tables), which carries another Panel (tablesOld) and on top of this is a JTable (olderTwoMonthTableModel). Tables has a pattern and this should be visible under tablesOld and olderTwoMonthTableModel.
 
Rancher
Posts: 3080
24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've read the question 3 times and I still am not sure exactly what you are trying to do. Posting fragments of code is not helpful.

Swing panels and layouts are 2-dimensional. If you want components "ot top" of one another, then you need to start using layered panes. So I would suggest you start by reading the section from the Swing tutorial on How to Use Layered Panes. Once you get this working you can work on opacity.

If at any time you have a problem then post a SSCCE (not your real application).

 
Switching from electric heat to a rocket mass heater reduces your carbon footprint as much as parking 7 cars. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!