博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
javafx官方文档学习之二Scene体系学习一
阅读量:6969 次
发布时间:2019-06-27

本文共 12878 字,大约阅读时间需要 42 分钟。

hot3.png

我的博文小站:,文章更新以博文小站为主,一般与oschina同步发布

原创文章,转载请注明出处,作者。

Package javafx.scene

Provides the core set of base classes for the JavaFX Scene Graph API.

See: Description

  •  

    Class Summary
    Class Description
    Camera

    Base class for a camera used to render a scene.

    Cursor

    A class to encapsulate the bitmap representation of the mouse cursor.

    Group

    Group node contains an ObservableList of children that are rendered in order whenever this node is rendered.

    GroupBuilder<B extends GroupBuilder<B>>

    Builder class for javafx.scene.Group

    ImageCursor

    A custom image representation of the mouse cursor.

    ImageCursorBuilder<B extendsImageCursorBuilder<B>>

    Builder class for javafx.scene.ImageCursor

    Node

    Base class for scene graph nodes.

    NodeBuilder<B extends NodeBuilder<B>>

    Builder class for javafx.scene.Node

    ParallelCamera

    Specifies a parallel camera for rendering a scene without perspective correction.

    Parent

    The base class for all nodes that have children in the scene graph.

    ParentBuilder<B extends ParentBuilder<B>>

    Builder class for javafx.scene.Parent

    PerspectiveCamera

    Specifies a perspective camera for rendering a scene.

    PerspectiveCameraBuilder<B extendsPerspectiveCameraBuilder<B>>

    Builder class for javafx.scene.PerspectiveCamera

    Scene

    The JavaFX Scene class is the container for all content in a scene graph.

    SceneAccessor
    SceneBuilder<B extends SceneBuilder<B>>

    Builder class for javafx.scene.Scene

    SnapshotParameters

    Parameters used to specify the rendering attributes for Node snapshot.

    SnapshotParametersBuilder<B extendsSnapshotParametersBuilder<B>>

    Builder class for javafx.scene.SnapshotParameters

    SnapshotResult

    This class holds the result of a snapshot operation.

  •  

    Enum Summary
    Enum Description
    CacheHint

    Cache hints for use with Node.cacheHint

    DepthTest

    This enum defines the possible states for the depthTest flag in node.

主要有顶级容器,Node节点基类,Parent分支节点基类,Group分支节点类,.节点渲染类Camera,鼠标光标类:Cursor,SnapShot类及其参数结果类。同时由于采用建造者模式,故而有对应的Builder类。

Package javafx.scene Description

Provides the core set of base classes for the JavaFX Scene Graph API. A scene graph is a tree-like data structure, where each item in the tree has zero or one parent and zero or more children.

The two primary classes in this package are:

  • Scene – Defines the scene to be rendered. It contains a fill variable(即fill属性,可用setFill()方法进行设置) that specifies the background of the scene, width andheight variables that specify the size of the scene, and a content sequence that contains a list of "root" Nodes to be rendered onto the scene. This sequence of Nodes is the scene graph for this Scene. A Scene is rendered onto a Stage, which is the top-level container for JavaFX content.

  • Node – Abstract base class for all nodes in the scene graph. Each node is either a "leaf" node with no child nodes or a "branch" node with zero or more child nodes. Each node in the tree has zero or one parent. Only a single node within each tree in the scene graph will have no parent, which is often referred to as the "root" node. There may be several trees in the scene graph. Some trees may be part of a Scene, in which case they are eligible to be displayed. Other trees might not be part of anyScene.

Branch nodes are of type Parent or subclasses thereof.

Leaf nodes are classes such as RectangleTextImageViewMediaView, or other such leaf classes which cannot have children.

A node may occur at most once anywhere in the scene graph. Specifically, a node must appear no more than once in the children list of a Parent or as the clip of a Node. See the Node class for more details on these restrictions.

public class Example extends Application {    @Override public void start(Stage stage) {                Group root = new Group();        Scene scene = new Scene(root, 200, 150);        scene.setFill(Color.LIGHTGRAY);        Circle circle = new Circle(60, 40, 30, Color.GREEN);                Text text = new Text(10, 90, "JavaFX Scene");        text.setFill(Color.DARKRED);                Font font = new Font(20);        text.setFont(font);                root.getChildren().add(circle);        root.getChildren().add(text);        stage.setScene(scene);        stage.show();    }    public static void main(String[] args) {        Application.launch(args);    }}

1. Node基类

Base class for scene graph nodes. A scene graph is a set of tree data structures 

javafx.scene.Node是这个树体系的基类。

继承体系:

  • .lang.Object

  • javafx.scene.Node

    • Direct Known Subclasses:

    • , , , , 

    • All Implemented Interfaces:

Each item in the scene graph is called a Node. Branch nodes are of type , whose concrete subclasses are , and , or subclasses thereof.

Leaf nodes are classes such as or other such leaf classes which cannot have children. 

以下规则是为了防止树体系无限循环交错的规则:

A node may occur at most once anywhere in the scene graph. Specifically, a node must appear no more than once in all of the following: as the root node of a , the children ObservableList of a , or as the clip of a .

The scene graph must not have cycles. A cycle would exist if a node is an ancestor of itself in the tree, considering the  content ObservableList,  children ObservableList, and  clip relationships mentioned above.

If a program adds a child node to a Parent (including Group, Region, etc) and that node is already a child of a different Parent or the root of a , the node is automatically (and silently) removed from its former parent. If a program attempts to modify the scene graph in any other way that violates the above rules, an exception is thrown, the modification attempt is ignored and the scene graph is restored to its previous state.

总之就是一个节点只能在树体系中最多出现一次。不能交错添加节点

关于线程注意事项:Node objects may be constructed and modified on any thread as long they are not yet attached to a . An application must attach nodes to a Scene, and modify nodes that are already attached to a Scene, on the JavaFX Application Thread.

关于节点标识ID:

String ID

Each node in the scene graph can be given a unique . This id is much like the "id" attribute of an HTML tag in that it is up to the designer and developer to ensure that the id is unique within the scene graph. A convenience function called can be used to find a node with a unique id within the scene graph, or within a subtree of the scene graph. The id can also be used identify nodes for applying styles; see the CSS section below.

节点变换:

Transformations

Any Node can have transformations applied to it. These include translation, rotation, scaling, or shearing.

translation rotation scaling shearing

边界矩形

Bounding Rectangles

 设置变量      

节点样式:

CSS

The Node class contains idstyleClass, and style variables that are used in styling this node from CSS. The id and styleClass variables are used in CSS style sheets to identify nodes to which styles should be applied. The style variable contains style properties and values that are applied directly to this node.

For further information about CSS and how to apply CSS styles to nodes, see the .

2 Parent分支节点基类与分支节点Group. Region,Control

Parent:public abstract class Parent extends Node

The base class for all nodes that have children in the scene graph.

This class handles all hierarchical scene graph operations, including adding/removing child nodes, marking branches dirty for layout and rendering, picking, bounds calculations, and executing the layout pass on each pulse.

There are three direct concrete Parent subclasses

  • Group effects and transforms to be applied to a collection of child nodes.

  • Region class for nodes that can be styled with CSS and layout children.

  • base Control class for high-level skinnable nodes designed for user interaction.(Control节点主要用户可以让用户来操作的节点,如按钮,文本框,可以与用户交互,用户可操作的节点。同时由于Control实现了Skinnable接口,故而可以轻松地设置皮肤,定制外观)

Group(Group一般作为根节点root)

@DefaultProperty(value="children")public class Groupextends Parent

Group node contains an ObservableList of children that are rendered in order whenever this node is rendered.

Group will take on the collective bounds of its children and is not directly resizable.

Any transform, effect, or state applied to a Group will be applied to all children of that group. Such transforms and effects will NOT be included in this Group's layout bounds, however if transforms and effects are set directly on children of this Group, those will be included in this Group's layout bounds.

By default, a Group will "auto-size" its managed resizable children to their preferred sizes during the layout pass to ensure that Regions and Controls are sized properly as their state changes. If an application needs to disable this auto-sizing behavior, then it should set autoSizeChildren to false and understand that if the preferred size of the children change, they will not automatically resize (so buyer beware!).

Group Example:

import javafx.scene.*;import javafx.scene.paint.*;import javafx.scene.shape.*;import java.lang.Math;Group g = new Group();for (int i = 0; i < 5; i++) {    Rectangle r = new Rectangle();    r.setY(i * 20);    r.setWidth(100);    r.setHeight(10);    r.setFill(Color.RED);    g.getChildren().add(r);}

Control:

Class Control相当于Layout布局器

  • java.lang.Object

    • javafx.scene.Parent

    • javafx.scene.control.Control

    • javafx.scene.Node

    • Direct Known Subclasses:

    • Accordion, ChoiceBox, ComboBoxBase, HTMLEditor, Labeled, ListView, MenuBar, Pagination, ProgressIndicator, ScrollBar,ScrollPane, Separator, Slider, SplitPane, TableView, TabPane, TextInputControl, ToolBar, TreeView

    • All Implemented Interfaces:

    • EventTarget, Skinnable

(Control节点主要用户可以让用户来操作的节点,如按钮,文本框,可以与用户交互,用户可操作的节点。同时由于Control实现了Skinnable接口,故而可以轻松地设置皮肤,定制外观)

关于Control节点的焦点转移focusTraversable

Most controls have their focusTraversable property set to true by default, however read-only controls such as Label andProgressIndicator, and some controls that are containers ScrollPane and ToolBar do not. 

Class Region相当于Layout布局器

  • Direct Known Subclasses:

  • Axis, Chart, Pane

  • Class Region

  • java.lang.Object

    • javafx.scene.Parent

    • javafx.scene.layout.Region

    • javafx.scene.Node

  • public class Regionextends Parent

    A Region is an area of the screen that can contain other nodes and be styled using CSS.

    It can have multiple backgrounds under its contents and multiple borders around its content. By default it's a rectangle with possible rounded corners, depending on borders. It can be made into any shape by specifying the shape. It is designed to support as much of the CSS3 specification for backgrounds and borders as is relevant to JavaFX. The full specification is available at css3-background.

    By default a Region inherits the layout behavior of its superclass, Parent, which means that it will resize any resizable child nodes to their preferred size, but will not reposition them. If an application needs more specific layout behavior, then it should use one of the Region subclasses: StackPaneHBoxVBoxTilePaneFlowPaneBorderPaneGridPane, or AnchorPane.

    To implement more custom layout, a Region subclass must override computePrefWidthcomputePrefHeight, and layoutChildrenNote thatlayoutChildren is called automatically by the scene graph while executing a top-down layout pass and it should not be invoked directly by the region subclass.

    Region subclasses which layout their children will position nodes by setting layoutX/layoutY and do not altertranslateX/translateY, which are reserved for adjustments and animation.

    • Direct Known Subclasses:

    • AxisChartPane

    • All Implemented Interfaces:

    • EventTarget

javafx.scene.web

Class WebView

  • java.lang.Object

    • javafx.scene.Parent

    • javafx.scene.web.WebView

    • javafx.scene.Node

    • All Implemented Interfaces:

    • EventTarget

extends Parent

WebView is a Node that manages a WebEngine and displays its content. The associated WebEngine is created automatically at construction time and cannot be changed afterwards. WebView handles mouse and some keyboard s, and manages scrolling automatically, so there's no need to put it into a ScrollPane.

WebView objects must be created and accessed solely from the FX thread.

Class ImageCursor

  • java.lang.Object

    • javafx.scene.ImageCursor

    • javafx.scene.Cursor

  • public class ImageCursorextends Cursor

    A custom image representation of the mouse cursor. On platforms that don't support custom cursors, Cursor.DEFAULT will be used in place of the specified ImageCursor.

    Example:

    import javafx.scene.*;import javafx.scene.image.*;Image image = new Image("mycursor.png");Scene scene = new Scene(400, 300);scene.setCursor(new ImageCursor(image,                                image.getWidth() / 2,                                image.getHeight() /2));

Class NodeBuilder<B extends NodeBuilder<B>>

  • java.lang.Object

    • javafx.scene.NodeBuilder<B>

  • @Generated(value="Generated by javafx.builder.processor.BuilderProcessor")public abstract class NodeBuilder
    >extends java.lang.Object

    Builder class for javafx.scene.Node

    • Direct Known Subclasses:

    • CanvasBuilder, ImageViewBuilder, MediaViewBuilder, ParentBuilder, ShapeBuilder

       

转载于:https://my.oschina.net/xby1993/blog/182594

你可能感兴趣的文章
[zz]LIS
查看>>
附加作业:源自刘乾老师的问题
查看>>
硬件篇之MMU
查看>>
如何打包成jar包自己看呢?
查看>>
不可变数组和可变数组
查看>>
Poj(2253),Dijkstra松弛条件的变形
查看>>
Poj(2195),最小费用流,SPFA
查看>>
shell编程系列4--有类型变量:字符串、只读类型、整数、数组
查看>>
WP开发笔记——去除 HTML 标签
查看>>
Json数据序列化对象,及对象序列化为Json格式
查看>>
vue.js的事件绑定与监听
查看>>
ipad%E5%A3%81%E7%BA%B81-1000x288.jpg
查看>>
浏览器兼容之旅的第一站:如何创建条件样式
查看>>
docker swarm英文文档学习-5-在swarm模式中运行Docker引擎
查看>>
利用NX Open在NX中创建点并获取点的坐标信息在listing_windows中输出
查看>>
【Erlang新手成长日记】JSON编码与解码
查看>>
Linux下安装tomcat和jdk
查看>>
实验四+065+方绎杰
查看>>
js中函数作用域,作用域链,变量提升
查看>>
c/c++ sizeof运算符详解以及对象大小
查看>>