问题
Its generic question. If I add some UI objects such as JButton etc and check the isVisible property, it would return true. However, does it guarantee that the object is actually rendered and visible correctly on the display? If not, is there some better way to check the same?
回答1:
No isVisible()
is only a hint for this component itself. If it is really visible for the user depends on the parent hierarchy of the component. This can be verified best by isShowing()
inherited by Component, which checks isVisible()
and isDisplayable()
of the component and all it's parent components. But as the javadoc mentions even that does not really guarantee that the component is really really visible to the user:
Note: sometimes there is no way to detect whether the Component is actually visible to the user. This can happen when:
the component has been added to a visible ScrollPane but the Component is not currently in the scroll pane's view port.
the Component is obscured by another Component or Container.
来源:https://stackoverflow.com/questions/16812112/does-isvisible-guarantees-the-visibility-of-the-ui-object-in-java