• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Issues arising from Glass Pane

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

Whilst I've been searching and reading these forums for a couple of months now, I've had to register as I've got an issue that Googling just can't fix!

I have a main panel on the frame, and a transparent glass panel over this. Here are the main steps in my program:

1) Glasspane visibility set to false. I then draw circles upon the main panel
2) Glasspane visibility set to true and update text on this (which should appear 'above' the circles)
3) Glasspane visibility set to false and I recolour these circles

Problem is, as soon as I update the text on the glasspanel, the circles beneath disappear, not appearing again until I redraw them. I know that I should be using threading, so I can't understand why this doesn't work:



Anybody got any tips? Thank you!
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure tha that you've posted enough code to help us figure out what's not working. I wonder if you're not doing your drawing in a JPanel (or other JComponent)'s paintComponent method?
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
.
 
Russell Tristen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Pete. My code is very large so reducing it down to a workable example will take a while, I'll get started. In the mean time, it may be useful to know that:

I draw the circles on the main panel by:



and I am 'drawing' on the glass panel by updating the text in a JLabel present on it:



I've had a look in a few of my reference books and is it possible that I need to override the glass pane's paint method? If I set it's visibility to true before I start drawing the circles, it appears beneath these circles. Why isn't the glass pane always staying on top?

Sorry about all the questions - I hope you can help me further! Thanks again.
 
Rancher
Posts: 3248
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I draw the circles on the main panel by: ....



And that is exactly what Pete suggested you should NOT be doing.

Custom painting is done by overriding the paintComponent() method. Read the section from the Swing tutorial on Custom Painting for more information, or search the forum/web for examples.
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And invokeLater can be (or should be) called only from EDT thread.

Use invokeAndWait (when calling from another thread) to do work in EDT, like the documentation says under the link...

And your above code can be written like
 
Sheriff
Posts: 22504
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mikko Kohtamäki wrote:And invokeLater can be (or should be) called only from EDT thread.


Nonsense. invokeLater can be called from any thread, including the EDT. It is used if you want something to be done on the EDT but it can finish at some later time. invokeAndWait cannot be called from the EDT (throws an exception), and is used if you need the GUI update to be done before continuing with the remainder of the thread.
 
Russell Tristen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all for your replies. I have done as suggested and all is now fixed
 
reply
    Bookmark Topic Watch Topic
  • New Topic