• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

.revalidate() not working as expected

 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Until recently, the revalidate() command at the end of this program worked fine, but then I changed the program a little bit,

and it does not work as expected. "Named" is a class that I made. When the user selects a certain node in the JTree (the node

which contains an object where toString() returns null), I expect the program to remove several JPanels which are on the

JPanel called rightPanel, and then add three JPanels called probPanel, testPanel, and unselectPanel, and then show the

changes to rightPanel.
What actually happens, is that the widget on ctypePanel and the widget on makeReportPanel are still visible, and although the

widgets on probPanel and testPanel are visible and active, the widget on unselectPanel is not visible. However, when the

mouse passes over the widget on ctypePanel, it changes to the widget on unselectPanel, and the button on makeReportPanel does

not do anything when clicked. So I think the ctypePanel and makeReportPanel are actually removed, and the unselectPanel is

actually added, but for some reason the changes are not shown on the computer screen, even though there is a revalidate()

command. Is there some reason why the revalidate() command does not show the changes to rightPanel?

 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try calling a repaint() after the revalidate()
 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. The repaint method needs a Rectangle object, and I'm not sure how to get one of those easily. Is there some kind of getRectangle method somewhere I can call to get a Rectangle which represents the JPanel? Or do I have to input four ints representing the position of the JPanel and height and width? Are the coordinates of the Rectangle relative to the JPanel, making the upper left corner of the JPanel equal to 0,0?
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The repaint() is heavily overloaded.
JPanel extends JComponent which extends Component.
Component has a repaint() with no arguments.
 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It worked! Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic