| Author |
.revalidate() not working as expected
|
Kevin Tysen
Ranch Hand
Joined: Oct 12, 2005
Posts: 255
|
|
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
Joined: Jul 26, 2007
Posts: 8434
|
|
|
Try calling a repaint() after the revalidate()
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
Kevin Tysen
Ranch Hand
Joined: Oct 12, 2005
Posts: 255
|
|
|
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
Joined: Jul 26, 2007
Posts: 8434
|
|
The repaint() is heavily overloaded.
JPanel extends JComponent which extends Component.
Component has a repaint() with no arguments.
|
 |
Kevin Tysen
Ranch Hand
Joined: Oct 12, 2005
Posts: 255
|
|
|
It worked! Thank you.
|
 |
 |
|
|
subject: .revalidate() not working as expected
|
|
|