• 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

Bad Background Refresh

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This is complicated to explain, but the gist is that the JVM is painting a JPanel to its background color when I don't want that to happen. Or, if I fix that, then one window's outline shows through and appears in the content area of a window that's on top of it.

The UI consists of a JFrame holding a JDesktopPane which holds three JInternalFrame objects. One of these JInternalFrame objects contains an instance of my own class, called STextArea. In some round-about way, the problem seems to be due the fact that STextArea starts a Timer, where each time that the Timer goes off, the action command sets a flag and calls repaint() for STextArea. This flag indicates that the next call to paintComponent() should only draw a caret (in xor mode) and draw nothing else. In the example code shown below, I just have paintComponent() do nothing and return when that flag is set rather than drawing the caret since the problem still manifests.

Here's the code -- I stripped it down as much as possible. If this is executed, you will see three sub-windows, where the one in the rear is titled Problem. Click on the Problem window to bring it to the front. The click on the Messages window at the lower-right to bring it to the front. You'll see that the refresh of the middle Messages window bleeds through to the content area of the Problem window. It bleeds through because of the calls to isOpaque(). However, if I get rid of those settings, then the call to STextArea.paintComponent() causes the JVM to fill the contents with the background color the first time that the Timer goes off.

 
Randall Fairman
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

To help give a more complete picture of what should happen, here's a code snippet that could be used in place of the STextArea.paintComponent() given above. It will flash a small yellow circle over the text, much like the way a caret blinks. The more fundamental problem(s) remain, but this shows the role of the Timer.

 
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 don't need all the synchronized methods. Swing painting code and Timer code is executed on the EDT which is single threaded.

I don't see the problems using JDK6_7 on XP.
 
Randall Fairman
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You don't see the problem? That's weird. I'm using XP and Java 1.6.0_26.

No matter what combination of setOpaque() values I use, I get some kind of strange behavior. Either the STextArea gets erased when the Timer trips or the window experiences bleed-through from a window that's behind it.
 
Randall Fairman
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

To make sure that there wasn't some problem with my IDE or some other oversight that I might have made due to my environment, I copied the code directly from the posting above to several .java files, then compiled and ran it from the command-line with javac and java. The problem is definitely there. Even if it's specific to my version of Java (which I have not tested), the fact that this problem arises at all is troubling. Either there's an error on my part (but I don't see it) or the idea of updating only a portion of a window, while leaving the rest unchanged, in response to a Swing Timer is off-limits as a strategy.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic