AWT的HierarchyListener和HierarchyEvent在JavaFX中的对应物是什么?

huangapple 未分类评论43阅读模式
英文:

What are AWT's HierarchyListener and HierarchyEvent Equivalents in JavaFX

问题

在Java AWT中,我们有能力添加一个HierarchyListener来接收组件的层次结构发生变化时的事件,当包含该容器的层次结构发生变化时。通过接收一个HierarchyEvent(表示Component所属的Component层次结构发生更改的事件),我们可以监听以下变化事件:

  • 层次结构变化事件(HierarchyListener)
    • 添加祖先
    • 移除祖先
    • 层次结构变得可显示
    • 层次结构变得不可显示
    • 层次结构在屏幕上显示(可见和可显示)
    • 层次结构在屏幕上隐藏(不可见或不可显示)
  • 祖先重塑事件(HierarchyBoundsListener)
    • 祖先被调整大小
    • 祖先被移动

示例代码:

JPanel panel = new JPanel();
panel.addHierarchyListener((event) -> {
    if((event.getChangeFlags() & HierarchyEvent.HIERARCHY_CHANGED) != 0) {
        // 层次结构树变化
    }
});

在JavaFX中如何监听相同类型的事件?例如,如何在JavaFX中在任何Node的祖先显示或隐藏时收到通知?

英文:

In Java AWT, we have the ability to add a HierarchyListener to receive hierarchy changed events from a component when the hierarchy to which that container belongs changes. By receiving a HierarchyEvent (An event which indicates a change to the Component hierarchy to which Component belongs), we can listen to the following change events:

  • Hierarchy Change Events (HierarchyListener)
    • Addition of an ancestor
    • Removal of an ancestor
    • Hierarchy made displayable
    • Hierarchy made undisplayable
    • Hierarchy shown on the screen (both visible and displayable)
    • Hierarchy hidden on the screen (either invisible or undisplayable)
  • Ancestor Reshape Events (HierarchyBoundsListener)
    • An ancestor was resized
    • An ancestor was moved

Sample code:

JPanel panel = new JPanel();
panel.addHierarchyListener((event) -> {
    if((event.getChangeFlags() & HierarchyEvent.HIERARCHY_CHANGED) != 0) {
        // hierarchy tree changed
    }
});

How can I listen to the same type of events in JavaFX? As an example, how can I get notified when any of a Node's ancestors get shown or hidden in JavaFX?

huangapple
  • 本文由 发表于 2020年4月4日 02:34:22
  • 转载请务必保留本文链接:https://java.coder-hub.com/61018346.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定