• Post Reply Bookmark Topic Watch Topic
  • New Topic

GUI Refresh Problem

 
Yogvinder Singh Ghotra
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • 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 .
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Which of paint or paintComponent is called?
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!