我是 JavaFX 新手,最近我在谷歌上搜索了一段时间以了解这一点。 我计划在我的 Swing 项目中重写现有的屏幕管理器框架。 我有兴趣了解 FX 中 JComponent 的替代方案是什么? 是舞台、窗口、控件还是父级,我无法得出结论。我也不确定是否有这样的替代方案。
为什么我需要 JComponent 的替代品? 好吧,在我现有的屏幕管理器框架中,我们总是将任何单个 swing 组件(例如面板)的类型返回为 JComponent。因此,如果我们有的话,我很想知道外汇领域的替代方案。
预先感谢您的帮助。
最佳答案
有点松散,相当于 JComponent是 Node
我说得比较宽松,因为它们是不同的事物,并且不是 100% 的等价关系,但我想您可以将它们视为大致代表相似的事物。节点比 JComponent 表示更多内容,因为它们可以表示形状、媒体 View 等。
JComponent 是:
The base class for all Swing components except top-level containers. To use a component that inherits from JComponent, you must place the component in a containment hierarchy whose root is a top-level Swing container. Top-level Swing containers -- such as JFrame, JDialog, and JApplet -- are specialized components that provide a place for other Swing components to paint themselves.
节点是:
Base class for scene graph nodes. A scene graph is a set of tree data structures where every item has zero or one parent, and each item is either a "leaf" with zero sub-items or a "branch" with zero or more sub-items.
请注意 Scene包含在 Window 中(或 Stage ),有点类似于 JComponent,窗口不是节点(但 JavaFX 显示的几乎所有其他内容都是)。
请参阅使用 Scene Graph Oracle 教程,了解有关节点是什么及其使用方式的更多信息。
关于javafx-2 - JavaFX 中 JComponent 的替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17792587/