• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

GUI Refresh Problem

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

I have a Swing Application the secription of which is as following :

The Frame contains Menu Bar and a JPanel(Main) only

JPanel itself has another JPanel(search) plus other Graphic 2D images like ellipse etc

the ellipses and connections between them are drawn based on some database values.

Main JPanel overrides paint, update methods.

Since the ellipse are based on database values any changes to these require updation to database and due to same .. all the components of main JPanel are removed and redrawn.

However due to this the Menu bar items become garbled i.e the search Jpanel starts showing at its location as well as above the menu items.

Please help .
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you triggering the repaint? Does it happen on the EDT? Are you calling super.paintComponent() in your overridden method?
 
Yogvinder Singh Ghotra
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the Main JPanel i have overridden paint and repaint methods and both are calling their respective super methods.
 
Yogvinder Singh Ghotra
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is happening is that ... I connect to a database... when i first connect to the database whatever is there in the Main panel is removed and added again (based on database values). however the newly added items may or may not be same.

when this happends overridden paint and repaint are not getting called instead i am calling overridden update method().
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why paint and repaint and update? Did you check the API? Aren't they interconnected?

Usually one just overrides the paintComponent.
Check out this example.
http://faq.javaranch.com/java/BackgroundImageOnJPanel
 
Yogvinder Singh Ghotra
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of paint or paintComponent is called?
 
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 unclear on what you mean by this:

Originally posted by Yogvinder Singh Ghotra:
Which of paint or paintComponent is called?



You need to read the JComponent API as well as the Sun graphics tutorials. They will tell you that both are called but have different responsibilities. Paint calls paintComponent, but it also is responsible for painting borders and child components, so if you are not manipulating these, you don't want to override paint but instead should override paintComponent (as was suggested above). Again, if this doesn't answer your question, then you should rephrase it as it is not clear in the least.
 
I child proofed my house but they still get in. Distract them with this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic