原創文章,轉載請註明出處,做者。
css
Provides the core set of base classes for the JavaFX Scene Graph API.html
See: Descriptionjava
Class Summary
Class | Description |
---|---|
Camera | Base class for a camera used to render a scene.node |
Cursor | A class to encapsulate the bitmap representation of the mouse cursor.css3 |
Group | A |
GroupBuilder<B extends GroupBuilder<B>> | Builder class for javafx.scene.Groupcanvas |
ImageCursor | A custom image representation of the mouse cursor.api |
ImageCursorBuilder<B extendsImageCursorBuilder<B>> | Builder class for javafx.scene.ImageCursororacle |
Node | Base class for scene graph nodes.app |
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 |
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 |
DepthTest | This enum defines the possible states for the depthTest flag in node. |
主要有Scene頂級容器,Node節點基類,Parent分支節點基類,Group分支節點類,.節點渲染類Camera,鼠標光標類:Cursor,SnapShot類及其參數結果類。同時因爲採用建造者模式,故而有對應的Builder類。
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 Rectangle
, Text
, ImageView
, MediaView
, 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是這個樹體系的基類。
繼承體系:
java.lang.Object
javafx.scene.Node
Each item in the scene graph is called a Node
. Branch nodes are of type Parent
, whose concrete subclasses are Group
, Region
, and Control
, or subclasses thereof.
Leaf nodes are classes such as Rectangle
, Text
, ImageView
, MediaView
, 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 Scene
, the children ObservableList of a Parent
, or as the clip of a Node
.
The scene graph must not have cycles. A cycle would exist if a node is an ancestor of itself in the tree, considering the Group
content ObservableList, Parent
children ObservableList, and Node
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 Scene, 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 Scene
. An application must attach nodes to a Scene, and modify nodes that are already attached to a Scene, on the JavaFX Application Thread.
關於節點標識ID:
Each node in the scene graph can be given a unique id
. 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 calledlookup(String)
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.
節點變換:
Any Node
can have transformations applied to it. These include translation, rotation, scaling, or shearing.
translation rotation scaling shearing
邊界矩形
設置變量boundsInLocal boundsInParent
layoutBounds
節點樣式:
The Node
class contains id
, styleClass
, 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 CSS Reference Guide.
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
A Group
node contains an ObservableList of children that are rendered in order whenever this node is rendered.
A 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:
java.lang.Object
javafx.scene.control.Control
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:
(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.
Direct Known Subclasses:
java.lang.Object
javafx.scene.layout.Region
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: StackPane
, HBox
, VBox
, TilePane
, FlowPane
, BorderPane
, GridPane
, or AnchorPane
.
To implement more custom layout, a Region subclass must override computePrefWidth
, computePrefHeight
, and layoutChildren
. Note 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:
All Implemented Interfaces:
javafx.scene.web
java.lang.Object
javafx.scene.web.WebView
All Implemented Interfaces:
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 events, 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.
java.lang.Object
javafx.scene.ImageCursor
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));
java.lang.Object
javafx.scene.NodeBuilder<B>
@Generated(value="Generated by javafx.builder.processor.BuilderProcessor") public abstract class NodeBuilder<B extends NodeBuilder<B>>extends java.lang.Object
Builder class for javafx.scene.Node
Direct Known Subclasses:
CanvasBuilder, ImageViewBuilder, MediaViewBuilder, ParentBuilder, ShapeBuilder