• 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
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

repaint a perticular panel.

 
Ranch Hand
Posts: 48
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you add components to a visible panel then you need to do:

 
Patil Niteen
Ranch Hand
Posts: 48
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 48
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic