aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes repaint a perticular panel. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "repaint a perticular panel." Watch "repaint a perticular panel." New topic
Author

repaint a perticular panel.

Patil Niteen
Ranch Hand

Joined: Dec 10, 2009
Posts: 48

Hi ranchers,

Suppose I have added 4 panels to a JFrame. On a perticular action I want to update the components of panel 1 only. Is there any way(method) through which I can repaint the panel 1 after updating its components . I tried with panel1.repaint(), but could not get the results. Or is it necessary to repaint the whole jFrame. Please giude me.

Thanks,


SCJP 1.4, SCWCD 5
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2091
    
    7
If you add components to a visible panel then you need to do:

Patil Niteen
Ranch Hand

Joined: Dec 10, 2009
Posts: 48

Hi Rob,
I tried the option specified by you but still could not get the required result.

To make my question more clear let us consider the example given below.

Suppose there are total 4 JPanels : mainPanel,statusInfoPanel,buttonPanel,dataPanel.

My class extends JFrame. The panels statusInfoPanel,buttonPanel and dataPanel are added to mainPanel.

Finally mainPanel is added to the JFrame.

Now, I want to change the contents of the data panel on the click of a specific button present on a buttonPanel . I will retreive the values from the database and will construct the JTable with this data and add this JTable to the dataPanel. I am trying to display the new data but could not do that. Am I missing something here? ,is dataPanel.repaint() sufficient to get the data cahange to be displayed? .

Or else do I have to construct the whole mainPanel and add it to JFrame?
Thanks.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2091
    
    7
and will construct the JTable with this data and add this JTable to the dataPanel.


There is no need to create a new JTable. All you need to do is update the existing table with a new TableModel. Something like:



If you need more help than you should create a SSCCE, that demonstrates the incorrect behaviour.
Patil Niteen
Ranch Hand

Joined: Dec 10, 2009
Posts: 48

Hi,

I have set the model for the JTable . Only table.revalidate();and table.repaint(); are sufficient to get the new data displayed or else we have to add the JTable to the mainPanel and the mainPanel to the JFrame and repaint all the panels. I have tried different ways but could not get the updated data displayed.

Which is the better approach?
Thanks.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2091
    
    7
I just gave you the 2 important lines of code. There is no need for a revalidate() or repaint().

And I don't see a SSCCE so I can't help anymore. Good luck.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: repaint a perticular panel.
 
Similar Threads
call to repaint() in paintComponent()
repaint problem in JPanel
Problem with custom painting and multiple JPanel
How to properly create an applet with an Input field and some shapes.
why repaint is not updating GUI?