Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Custom RepaintManager example  RSS feed

 
Rahul Saple
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I recently have started to read a book called Filthy Rich Clients......... There is an example in that book which depicts how the default action of the default RepaintManager can cause problems in some cases.... The example adds a table and three buttons to a TranslucentPanel, which in turn is added to the frame's content pane......Inside the TranslucentPanel's paint method an image of the content pane is created with an added alphavalue of 0.2f and is drawn on top of the frame.... But due to the default nature of the RepaintManager, as soon as you hover over a button or click on the table, the component suddenly turns opaque.... I tried rectifying this problem with a customized version of the RepaintManager which works very wierdly(for me). The whole Panel, with each click, goes on turning a little opaque and it takes about 5 clicks to
make it completely opaque. Can anybody in here help me with this?... Thanks..... Here's the problematic code

[ March 13, 2008: Message edited by: rahul saple ]
 
Brian Cole
Author
Ranch Hand
Posts: 947
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rahul saple:
I tried rectifying this problem with a customized version of the RepaintManager which works very wierdly(for me). The whole Panel, with each click, goes on turning a little opaque and it takes about 5 clicks to
make it completely opaque. Can anybody in here help me with this?...


Five repaints to complete opaqueness makes sense if you're painting
with a 0.2 alpha each time. Depending on what exactly you are trying
to do, you could try clearing the background with something like:

g2 = (Graphics2D) g.create();
g2.setBackground(getBackground());
g2.clearRect(0, 0, getWidth(), getHeight());

g2.setComposite(AlphaComposite.SrcOver.derive(0.2f));
g2.drawImage(image, 0, 0, null);

btw, you could replace that while(parent instanceof JComponent) loop
with a single call to SwingUtilities.getAncestorOfClass(TranslucentPanel.class, comp).
 
Rahul Saple
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Brian Cole:


Five repaints to complete opaqueness makes sense if you're painting
with a 0.2 alpha each time.


Thanks Brian ........it seems to be working now but i am still a little confused as to why the program reacted the way it did.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!