2

I'm writing a program that uses a few components in a GUI. However, I don't need all of them showing at the same time. In addition, depending on the user's input, there may be times once a component is not in use anymore, that it may or may not be needed again.

So far I have simply just invoked setVisible(false) for each component that I do want to show on the screen. If they are needed again, i simply make them visible.

My question is this. Does setting a component's visibility to false have major implications on performance of a program (generally speaking)? Does the paintComponent method paint a component that is not visible and then just does not show it, or does it ignore it all together?

Also, is it better to just to remove the component from a container instead?

4

1 回答 1

0

If it is not visible it not being drawn. Lets say I made a button and then made it so it prints "Hello" when I press it. If the button setVisible() is false I won't be able to click on it, its not their.

于 2013-04-11T03:42:27.017 回答