Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java paint() help

Status
Not open for further replies.

Gaffi84

Programmer
May 18, 2009
5
0
0
US
We are using JPanes in a JTabbedPane for a web interface application.

When switching to a tab in the JTabbedPane that already has Graphics2D components drawn on a JPane (lines, etc.), the drawn information disappears.

We currently have the paint() method overrided in the JPane where we are actually drawing graphics.

One work around we have tried was to place code in the JTabbedPane's componentlistener to run when it detects we've switched tabs. That didn't work as the code that runs is done prior to the final refresh of the JTabbedPane, which removes any drawn information.

We had to place a refresh button on the JPane for the user to click (or any other even trigger) to re-draw the information in order for the image/graphics to be seen.

How can we avoid this event-only displaying of our graphics? Is there another tab-switching trigger we are unaware of?

Code examples are available if necessary, but it's a little messy since the tabs are each their own class.

Thanks much.
 
Will the first input component(Other than the tab) of each JTabbedPane get the default focus?
When first input component change from no focus to getfocus), call code that refresh button do.
 
I'm sorry, but I don't think I fully understand your question.

The way it is set up now, there is no focus being explicitly set on the JPanel when a tab is changed.

To be more specific about the problem, we have a tab set up with a drawn diagram and a list of items (JList). When the user selects an item from the list, the diagram changes.

However, if the user moves to another tab and decides to come back, the diagram that was last displayed will no longer be there.

The selection on the list remains the same, but the 'refresh' code must be manually run to see the diagram again (or else choose another item from the list).
 
This is my suggestion.
When users swich to different JPanes, they want to see different result of drawing. I will call refresh or my piece of code that redraw the diagram. (like clicking on different channel buttons on tv remote control)

Either your JLists are class object or you use class variable to store the input figures of JList, you will have the input to draw the diagram after user has changed JPane by clicking the tab.
Please clarify if I misunderstand.
 
Ok, so we have mostly figured it out. We were not properly overriding the paint method in this class (left out @Override), but we thought we were. The only 'problem' now is that the draw space flickers when refreshing, though it all does display correctly.

Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top