• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot super.paintComponents(g) of JDialog  RSS feed

 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


There is no super.paintComponent(g) to call within JDialog, but it is overridable?
And also setOpaque is not allowed too.
How come?
Thanks
Jack
 
m Korbel
Ranch Hand
Posts: 174
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- painting to Top-Level Containers (inherits, nested on AWT methods) is accesible only from AWTs paint()

- put there JPanel (in the case that will be container for JComponents) or plain JComponent

- by default there isn't any problem to painting transparent or translucent image in Swing

- note thre are a few awfull changes for translucency in Java7, important is code ordering, changing L&F for decorated Top-Level Containers isn't possible without dirty hacks
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are overriding paintComponents() and not paintComponent() - note the 's' .
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard Tookey wrote:You are overriding paintComponents() and not paintComponent() - note the 's' .


Hello Richard,
Okay, I see that typo.
But there aren't any setOpaque to call. Do I use setOpacity(1.0); instead?
Thanks
Jack
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacky Luk wrote:
Richard Tookey wrote:You are overriding paintComponents() and not paintComponent() - note the 's' .


Hello Richard,
Okay, I see that typo.
But there aren't any setOpaque to call. Do I use setOpacity(1.0); instead?
Thanks
Jack


As always you use whatever methods the component allows! Check the Javadoc.
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know why I have new'ed the color1 property, but I
still get null pointer exception.
Does anyone spot any errors?
I also wonder do I override paintComponent(Graphics g) instead, but I don't think there is one to override.
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- you are ignoring (btw as always) all mentioned points in previous posts

- your code is GPU killer, don't to set whatever different as paitning in paint, paintComponent, paintChildren

- again put there JPanel override paintComponent

EDIT

- never extends anything, nor Top-Level Containers

- code ordering should be (as aside note in Java7 isn't possible to create undecorated container) important, runnable in Java7,I'm leaving important workaroung for Java7

 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry, Korbel.
And thanks
Jack
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The gradient paint works now.
But One problem I am facing is when I override the paint method of JDialog
and adding JPanels and JLayeredPane's to this JDialog
The original contents of the JPanels and JLayeredPane's are overwritten,
How can I make the Gradient stay in the background?
Thanks
Jack
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While using Swing, it is recommended you override paintComponent instead of paint. In this case the contentPane's paintComponent should be overridden.

All the panels you add to the dialog should be set to setOpaque(false) for the gradient paint to show.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!