gpt4 book ai didi

java - JComponent.isShowing() 和 isDisplayable() 之间的区别

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:54:20 26 4
gpt4 key购买 nike

Component.isShowing() 之间有什么区别?和 Component.isDisplayable() ?我想用它们来决定我是否应该停止/启动计时器。

最佳答案

一个组件
isShowing()

Determines whether this component is showing on screen. This means that the component must be visible, and it must be in a container that is visible and showing.

isShowing() 是递归的并且也检查所有父组件,但是 isDisplayable()isVisible() 只验证组件,而不是其父级的状态。

这意味着您的组件当前显示在屏幕上的框架、面板等内。
setVisible(true) --> isShowing() 返回 true(大多数情况下)
setVisible(false) --> isShowing() 返回 false(在所有情况下)

isDisplayable()

Determines whether this component is displayable. A component is displayable when it is connected to a native screen resource.

A component is made displayable either when it is added to a displayable containment hierarchy or when its containment hierarchy is made displayable. A containment hierarchy is made displayable when its ancestor window is either packed or made visible.

A component is made undisplayable either when it is removed from a displayable containment hierarchy or when its containment hierarchy is made undisplayable. A containment hierarchy is made undisplayable when its ancestor window is disposed.

这意味着您的组件处于可以显示在屏幕上的状态,但不需要当前显示在屏幕上即可处于 displayable 状态。例如,即使之前在组件上调用了 setVisible(false)(因此该组件是“不可见的”),该组件仍然是 displayableisDisplayable() 将返回 true。

关于java - JComponent.isShowing() 和 isDisplayable() 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11968780/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com