JavaFX 1.3.1 API | Overview | Java FX
| com.javafx.preview.control |
This package contains a collection of experimental/preview controls that are not final and will change in future releases.
This package contains a collection of experimental/preview controls that are not final and will change in future releases. Eventually it is intended that these controls will transition from the com.javafx.preview.control package to the javafx.scene.control package. These controls have been made available for early adopters to experiment with in the hopes that doing so will provide useful feedback to help make the JavaFX UI Controls library the most powerful and pleasing UI Controls library available. If you have any feedback on these controls, either as requests for enhancement or as bug reports, please report them all to the JavaFX JIRA issue tracker. For more information on the official controls that are part of the JavaFX
release, as well as details on the controls architecture and how to style
controls, refer to the |
||||||||||||||||||||||||||||||||||||
| com.javafx.preview.layout | |||||||||||||||||||||||||||||||||||||
| javafx.animation |
The
The The two primary classes in this package are:
Each variable in the These interpolated variables can then be used to control various rendering attributes (such as position), or for any other use desired by the application. For example:
import javafx.animation.Timeline;
import javafx.animation.KeyFrame;
var x:Number;
var tl = Timeline {
keyFrames: [
KeyFrame {
time: 0s
values: x => 1.0
}
KeyFrame {
time: 2s
values: x => 5.0
}
]
}
When the above Note that the JavaFX compiler has built-in support for animation.
Along with the
import javafx.animation.Timeline;
var x:Number;
var tl = Timeline {
keyFrames: [
at(0s) { x => 1.0 }
at(2s) { x => 5.0 }
]
}
In addition to defining key values, a For example:
import javafx.animation.Timeline;
import javafx.animation.KeyFrame;
import javafx.animation.Interpolator;
var x:Number;
var y:Number;
var tl = Timeline {
repeatCount: Timeline.INDEFINITE
keyFrames: [
at(0s) { x => 1.0; y => 3.0 }
at(2s) { x => 4.0 }
at(4s) { x => 5.0; y => 12.0 tween Interpolator.EASEBOTH }
KeyFrame {
time: 4s
action: function() {
println("done with cycle");
}
}
]
}
In this example, Note that this |
||||||||||||||||||||||||||||||||||||
| javafx.animation.transition |
Provides the set of classes for ease of use transition based animations.
Provides the set of classes for ease of use transition based animations. It offers a simple framework for incorporating animations onto an internal Timeline. It also provides high level constructs to compose the effects of multiple animations. |
||||||||||||||||||||||||||||||||||||
| javafx.async |
Provides the set of classes for javafx.async.
Provides the set of classes for javafx.async. This package provides the ability to run application code on threads other than the JavaFX event dispatch thread. The ability to control the execution and track the progress of the application code is also provided. |
||||||||||||||||||||||||||||||||||||
| javafx.data | |||||||||||||||||||||||||||||||||||||
| javafx.data.feed |
This package contains the base classes for an Atom or RSS document.
This package contains the base classes for an Atom or RSS document. |
||||||||||||||||||||||||||||||||||||
| javafx.data.feed.atom |
This package contains all the data structures for parsing a document that conforms to the Atom Syndication Format
This package contains all the data structures for parsing a document that conforms to the Atom Syndication Format |
||||||||||||||||||||||||||||||||||||
| javafx.data.feed.rss |
This package contains all the data structures for parsing an RSS document.
This package contains all the data structures for parsing an RSS document. |
||||||||||||||||||||||||||||||||||||
| javafx.data.pull | |||||||||||||||||||||||||||||||||||||
| javafx.data.xml | |||||||||||||||||||||||||||||||||||||
| javafx.date | |||||||||||||||||||||||||||||||||||||
| javafx.ext.swing |
Provides the set of graphical user interface component classes that, to the maximum degree possible, work the same on all platforms.
Provides the set of graphical user interface component classes that, to the maximum degree possible, work the same on all platforms. This is a second paragraph test. |
||||||||||||||||||||||||||||||||||||
| javafx.fxd |
Provides functionality to load JavaFX graphic files (FXD and FXZ format) that are generated by JavaFX Production Suite.
Provides functionality to load JavaFX graphic files (FXD and FXZ format) that are generated by JavaFX Production Suite. JavaFX graphic format files contains text descriptions of the graphical content of the JavaFX application. Descriptions are loaded by this package into the application during runtime. JavaFX graphic format exists in two forms, FXD and FXZ. FXD is a textual format using the same object literal syntax as JavaFX Script, so it is possible to copy and paste the descriptions from the FXD file directly into JavaFX Script code (with some exceptions noted at the end of this section). Here is an example of a simple FXD file representing a smiley face graphic:
FXD {
content: [
Circle { id:"background" centerX:40 centerY:40 radius:39
fill:Color.YELLOW stroke:Color.BLACK strokeWidth:3.0},
Circle { centerX:25 centerY:30 radius:5 fill: Color.BLACK},
Circle { centerX:55 centerY:30 radius:5 fill: Color.BLACK},
Line{ startX:32 startY:23 endX:16 endY:15 stroke:Color.BLACK strokeWidth:4.0},
Line{ startX:45 startY:23 endX:61 endY:15 stroke:Color.BLACK strokeWidth:4.0},
QuadCurve { id: "mouth" stroke:Color.BLACK strokeWidth:3.0 fill: Color.TRANSPARENT
startX:20 startY:60 endX:60 endY:60 controlX:40 controlY:80
}
]
}
The content is loaded using the javafx.fxd.FXDLoader class. It
can be inserted into the scene graph using this snippet of code:
var group:Group .... // a graphics group defined elsewhere
var smileyNode = FXDLoader.load("{__DIR__}smiley.fxd"}; // loads the content
insert smileyNode into group.content; // inserts the smiley into the group
It is possible to reference external assets from FXD content. The FXD description
follows the same approach as JavaFX Script, using the {__DIR__} magic variable.
The following example demonstrates how to reference embedded font and image files
in the FXD description. All of the files are stored in an FXZ file called mygfx.fxz:
FXD {
content: [
ImageView { x: 10 y: 10
image: Image{ url: "{__DIR__}myimage.png"}
},
Text { fill: Color.WHITE x: 20 y: 20 textOrigin: TextOrigin.TOP
font: Font.fontFromURL("{__DIR__}myfont.ttf", 25.00)
content: "Welcome !!!"
},
]
}
In the above example, the root contains two nodes - ImageView with
Image, which loads its content from the myimage.png file. The other node is a Text
node and it uses a custom font with size 25. The font is loaded from the myfont.ttf
file. Both, the image and the font files are located in the same
directory as the mygfx.fxd file itself.
FXZ is simply a compressed version of the FXD content using zip compression
and file format. The FXZ file can also contain embedded assets, such as images or fonts.
The structure of the FXZ file from the example above is as follows:
mygfx.fxz +- content.fxd +- myimage.png +- myfont.ttf +- ...The content.fxd file is the main content of the FXZ archive, containing the description of the graphic objects. The other
files, myimage.png and myfont.ttf are the embedded image and font assets.
FXZ files can be loaded in exactly the same way as FXD files, using
the javafx.fxd.FXDLoader class.
FXD format follows similar object literal syntax as JavaFX Script.
This makes FXD format highly compatible with JavaFX Script, and it
is possible to copy portions of the FXD content directly to the JavaFX script code.
Detailed FXD format specification is available here.
|
||||||||||||||||||||||||||||||||||||
| javafx.geometry |
Provides the set of 2D classes for defining and performing operations on objects related to two-dimensional geometry.
Provides the set of 2D classes for defining and performing operations on objects related to two-dimensional geometry. |
||||||||||||||||||||||||||||||||||||
| javafx.io |
Provides basic IO facility for JavaFX scripts.
Provides basic IO facility for JavaFX scripts. The main areas of functionality of
|
||||||||||||||||||||||||||||||||||||
| javafx.io.http |
This package contains the classes for communicating via HTTP.
This package contains the classes for communicating via HTTP. |
||||||||||||||||||||||||||||||||||||
| javafx.lang |
This package provides JavaFX Script Runtime APIs
This package provides JavaFX Script Runtime APIs
BuiltinsThis class is automatically imported to all JavaFX ScriptsFXThe FX class contains number of static entry points for a couple of different API sets provided by JavaFX Script.
|
||||||||||||||||||||||||||||||||||||
| javafx.reflect |
Provides reflective access to JavaFX values and types.
Provides reflective access to JavaFX values and types. This packages defines a Java API (rather than a JavaFX API), so it can be used from both Java and JavaFX code. A future JavaFX API may be layered on top of this. ContextThe objects in this package are directly or indirectly created from a FXContext. In the default case there is a singleFXContext instance that
uses Java reflection. You get one of these by doing:
FXLocal.Context ctx = FXLocal.getContext();Alternatively, you can do: FXContext ctx = FXContext.getInstance();The latter is more abstract (as it supports proxying for remote VMs) but the more specific FXLocal.Context supports some extra
operations that only make sense for same-VM reflection.
ValuesThe various reflection operations do not directly use Java values. Instead, an javafx.reflect.FXObjectValue is ahandleor proxy for an Object. This extra layer of indirection
isn't needed in many cases, but it is useful for remote invocation,
remote control, or in general access to data in a different VM.
Object creationTo do the equivalent of the JavaFX code:
you can do:
Sequence operationsUse javafx.reflect.FXSequenceBuilder to create a new sequence. To get the number of items in a sequence, use ValueRef.getItemCount. To index into a sequence, use ValueRef.getItem. Design notes and issuesSome design principles, influenced by the "Mirrored reflection" APIs (Bracha and Ungar: Mirrors: Design Principles for Meta-level Facilities of Object-Oritented Programming Languages, OOPSLA 2004), and JDI :
Limitations
|
||||||||||||||||||||||||||||||||||||
| javafx.runtime | |||||||||||||||||||||||||||||||||||||
| javafx.scene |
Provides the core set of base classes for the JavaFX Scene Graph API.
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:
Branch nodes are of type Parent, whose concrete subclasses are Group, javafx.scene.layout.Container, javafx.scene.control.Control, CustomNode, or subclasses thereof. Leaf nodes are classes such as javafx.scene.shape.Rectangle, javafx.scene.text.Text, javafx.scene.image.ImageView, javafx.scene.media.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: in the content sequence of a Scene, in the children sequence of a Parent (for example, in a Group node's content sequence), or as the clip of a Node. See the Node class for more details on these restrictions. ExampleAn example JavaFX scene graph is as follows:
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
Scene {
width: 200
height: 150
fill: Color.LIGHTGRAY
content: [
Circle {
centerX: 60
centerY: 40
radius: 30
fill: Color.GREEN
},
Text {
x: 10
y: 90
font: Font { size: 20 }
content: "JavaFX Scene"
fill: Color.DARKRED
}
]
}
The above example will generate the following image: ![]() Coordinate System and TransformationsThe Any See the Node class for more information on transformations. Bounding RectangleSince every Each
See the Node class for more information on bounding rectangles. CSS
The JavaFX Scene Graph provides the facility to style nodes using
CSS (Cascading Style Sheets).
The Node class contains For further information about CSS, how to apply CSS styles to nodes, and what properties are available for styling, see the CSS Reference Guide. |
||||||||||||||||||||||||||||||||||||
| javafx.scene.chart |
The JavaFX User Interface provides a set of chart components that are a very convenient way for data visualization.
The JavaFX User Interface provides a set of chart components that are a very convenient way for data visualization. Application developers can make use of these off-the-rack graphical charts provided by the SDK, to visualize a wide variety of data. Commom types of charts such as Bar, Line, Area, Pie, Scatter and Bubble charts are provided. These charts are easy to create and are customizable. JavaFX Charts API is a visual centric API rather than model centric. There are several public variables provided for charts that can be customized either programmatically or via CSS. JavaFX Charts API is modular and extendable. PieChart3D and BarChart3D are two such examples that extend from PieChart and BarChart respectively to form new Chart types. Below is a table listing the existing Chart types and a brief summary of their intended use.
The javafx.scene.chart.Chart is the baseclass for all charts. It is responsible for drawing the background, frame, title and legend. It can be extended to create custom chart types. The javafx.scene.chart.XYChart is the baseclass for all two axis charts and it extends from Chart class. It is mostly responsible for drawing the two axis and the background of the chart plot. Most charts extend from XYChart class except for PieChart which extends from Chart class as it is not a two axis chart. The javafx.scene.chart.part package includes axis classes that can be used when creating two axis charts. javafx.scene.chart.data.Axis is the abstract base class of all chart axis. javafx.scene.chart.part.CategoryAxis plots string categories where each value is a unique category along the axis. javafx.scene.chart.NumberAxis plots a range of numbers with major tick marks every tickUnit. The javafx.scene.chart.data package has Data and Series classes that are used as a basis for defining chart data. Chart contains one or several series of data. For Example BarChart plots data from a sequence of javafx.scene.chart.BarChart.Series objects. Each series contains javafx.scene.chart.BarChart.Data objects.
def barSeries1: BarChart.Series = BarChart.Series {
name: "Anvils"
BarChart.Data {
Category: "2007"
Value: 567
}
}
We can define more series objects similarly. Following code snippet shows how to create a BarChart with 3 categories and its X and Y axis:
def barchart = BarChart {
title: "Title" titleFont: Font { size: 24 }
categoryAxis: CategoryAxis {
categories: ["2007", "2008", "2009"]
}
valueAxis: NumberAxis {
label: "Units Sold"
UpperBound: 3000
tickUnit: 1000
}
data: [barSeries1, barSeries2, barSeries3]
}
JavaFX charts lends itself very well for real time or dynamic Charting (like online stocks, web traffic etc) from live data sets. Here is an example of a dynamic chart created with simulated data. A javafx.animation.Timeline is used to simulate dynamic data for temperature variations over time(Days).
def DISPLAY_RANGE:Integer = 50;
def xAxis:NumberAxis = NumberAxis {
label: "Time (Days)"
lowerBound: 0
upperBound: DISPLAY_RANGE
tickUnit: DISPLAY_RANGE/10
formatTickLabel: function(value):String { "{(value as Float) as Integer}" }
};
public def CHART = LineChart {
title: "Dynamic Data Sample"
data: LineChart.Series{
name: "Random"
};
xAxis: xAxis
yAxis: NumberAxis {
label: "Temperature"
lowerBound: -40
upperBound: 100
tickUnit: 20
}
}
var currentDay = 0;
def timeline:Timeline = Timeline{
repeatCount: Timeline.INDEFINITE
keyFrames: KeyFrame {
time: 0.2s
action: function() {
if (currentDay > DISPLAY_RANGE) {
delete series.data[0];
xAxis.lowerBound = currentDay-DISPLAY_RANGE;
xAxis.upperBound = currentDay;
}
insert LineChart.Data{
xValue: currentDay
yValue: (javafx.util.Math.random() * 130) -35
} into series.data;
currentDay ++;
}
}
}
|
||||||||||||||||||||||||||||||||||||
| javafx.scene.chart.data | |||||||||||||||||||||||||||||||||||||
| javafx.scene.chart.part | |||||||||||||||||||||||||||||||||||||
| javafx.scene.control |
The JavaFX User Interface Controls (UI Controls or just Controls) are specialized Nodes in the JavaFX Scenegraph especially suited for reuse in many different application contexts.
The JavaFX User Interface Controls (UI Controls or just Controls) are specialized Nodes in the JavaFX Scenegraph especially suited for reuse in many different application contexts. They are designed to be highly customizable visually by designers and developers. They are designed to work well with layout systems, and to be useful for mobile, desktop, web, and tv applications. Examples of prominent controls include Button, Label, ListView, and TextBox. Since Controls are Nodes in the scenegraph, they can be freely mixed with Containers, Groups, Images, Media, Text, and basic geometric shapes. While writing new UI Controls is not trivial, using and styling them is very easy, especially to existing web developers. Below is a table listing the existing UI Controls and a brief summary of their intended use.
In addition to the Controls listed here, there are a variety of helper
classes and mixins which the UI Controls library uses extensively, such as
Labeled, Cell and ToggleGroup. There are also
a number of preview controls which are available in the
The remainder of this document will describe the basic architecture of the JavaFX UI Control library, how to style existing controls, write custom skins, and how to use controls to build up more complicated user interfaces. ArchitectureControls follow the classic MVC design pattern. The Control is the "model". It contains both the state and the functions which manipulate that state. The Control class itself does not know how it is rendered or what the user interaction is. These tasks are delegated to the Skin ("view") and Behavior ("controller") classes respectively. All Controls extend from the Control class, which is in turn a Parent node, and which is both a Resizable and a TextOffsets (for purposes of baseline alignment). Every Control has a reference to a single Skin, which is the view implementation for the Control. The Control delegates to the Skin the responsibility of computing the min, max, and pref sizes of the Control, the baseline offset, and hit testing (containment and intersection). The Control delegates to the Behavior all handling of key events which occur on the Control when it contains the focus. Other than these clearly defined points of delegation, there should be no communication from a Control to a Skin or a Behavior. In general, the Control worries only about modifying its own internal state. These state changes may be exposed to the Skin via bindings or layout changes. Rather than having the Control push change notification to the Skin, it is the responsibility of the Skin to observe state changes on the Control by using binding. Likewise, the Behavior should be decoupled from the Skin such that it does not communicate directly with a Skin. Instead, the Skin calls functions on the behavior in response to input events, and the Behavior then modifies state on the control (typically by invoking some function on the control which mutates the control's state). Thus, when state on the Model (Control) changes, the View (Skin) is notified via binding and then updates accordingly. When user interaction occurs on the View (Skin), it notifies the Controller (Behavior) which then may mutate state on the Model (Control). ControlControl extends from Parent, and as such, is not a leaf node. From the perspective of a developer or designer the Control can be thought of as if it were a leaf node in many cases. For example, the developer or designer can consider a Button as if it were a Rectangle or other simple leaf node. Since it is a Resizable, a Control
will be auto-sized to its preferred size on each scenegraph
pulse. Setting the width and height of the Control does not affect its
preferred size. When used in a layout container, the layout constraints
imposed upon the Control (or manually specified on the Control) will
determine how it is positioned and sized. In general, any Node in the
scenegraph can be given a preferred size by setting LayoutConstraints on the
Node. See the The Skin of a Control can be changed at any time. Doing so will mark the Control as needing to be laid out since changing the Skin likely has changed the preferred size of the Control. If no Skin is specified at the time that the Control is created, then a default CSS-based skin will be provied for all of the built-in Controls. Each Control may have an optional tooltip specified. The Tooltip is a Control which displays some (usually textual) information about the control to the user when the mouse hovers over the Control from some period of time. It can be styled from CSS the same as with other Controls.
The getMinWidth, getMinHeight, getPrefWidth, getPrefHeight, getMaxWidth, and getMaxHeight functions are delegated directly to the Skin. The baselineOffset variable is delegated to the node of the skin. It is not recommended that subclasses alter these delegations. As with all Resizables, the layoutBounds is defined to be based on the width and height of the Resizable. It is not recommended to change this definition in subclasses. SkinSkin is the abstract class which represents the "view", or visuals, of a Control. The Control itself is not responsible for its visual representation but instead delegates this to the Skin. The Control contains no visual state. There are a few notable exceptions such as textFill on Label and font on Labeled. Typically, visual state resides solely on a Skin implementation and is set or manipulated from CSS. This design is crucial for allowing for wildly different Skin implementations. The Skin has a readonly reference to the Control it is currently assigned to. A single Skin instance can be used on one and only one Control at a time. The Skin also maintains a reference to the Behavior associated with that Skin. The behavior variable is readonly, but can be set by Skin subclasses. It is the responsibility of the subclass to specify which Behavior it uses. Default implementations of the getMinWidth, getMinHeight, getPrefWidth, getPrefHeight, getMaxWidth, and getMaxHeight functions exist in the Skin class. By default, the min width and height is 0, the pref width is 100, the pref height is 50, and the max width and height is Float.MAX_VALUE. While the min and max defaults are reasonable, the pref width and height defaults were chosen so as to be something roughly reasonable (ie: not zero). The rationale was to make it easier to get a basic Skin implementation up and running. However, these defaults hide an error condition. It is the responsibility of a Skin implementation to implement the getPrefWidth and getPrefHeight functions, otherwise the Control will always default to be 100 x 50 (and by virtue of auto-sizing, will be forced to be this size if not given different preferred widths and heights). It would be cleaner to have made these functions abstract. In a subsequent release these may be made abstract. Skin implementations must always override the getPrefWidth and getPrefHeight functions. It is an error in the implementation of the Skin subclass if these functions are not overridden. BehaviorThe last main architectural element is the Behavior class. The Behavior is responsible for implementing the user interaction logic of the Control. For example, the Button's behavior is responsible for handling the press-arm-release semantics used with Buttons. The Control delegates all keystrokes to the Behavior when the Control has the focus. The Skin delegates all mouse events or other input events that it receives to the Behavior so that the behavior may implement the user interaction logic of the Control and modify state on the Control as necessary. The Behavior API itself is principally comprised of a single function callActionForEvent which is called from the Control whenever a key event occurs on that Control. This function is not abstract, but under normal circumstances a subclass of Behavior will want to override this function and provide an implementation, otherwise keystrokes would not be correctly setup for use for that Control. Styling ControlsThere are two methods for customizing the look of a Control. The most difficult and yet most flexible approach is to write a new Skin for the Control which precisely implements the visuals and behaviors which you desire for the Control. Consult the Skin documentation for more details. The easiest and yet very powerful method for styling the built in Controls is by using CSS. Please note that in this release the following CSS description applies only to the default Skins provided for the built in Controls. Subsequent releases will make this generally available for any custom third party Controls which desire to take advantage of these CSS capabilities. Each of the default Skins for the built in Controls is comprised of multiple individually styleable areas or regions. This is much like an HTML page which is made up of <div>'s and then styled from CSS. Each individual region may be drawn with backgrounds, borders, images, padding, margins, and so on. The JavaFX CSS support includes the ability to have multiple backgrounds and borders, and to derive colors. These capabilities make it extremely easy to alter the look of Controls in JavaFX from CSS. The colors used for drawing the default Skins of the built in Controls are all derived from a base color, an accent color and a background color. Simply by modifying the base color for a Control you can alter the derived gradients and create Buttons or other Controls which visually fit in with the default Skins but visually stand out.
As with all other Nodes in the scenegraph, Controls can be styled by using an external stylesheet, or by specifying the style directly on the Control. Although for examples it is easier to express and understand by specifying the style directly on the Node, it is recommended to use an external stylesheet and use either the styleClass or id of the Control, just as you would use the "class" or id of an HTML element with HTML CSS. Each UI Control specifies a styleClass which may be used to style controls from an external stylesheet. For example, the Button control is given the "button" CSS style class. The CSS style class names are hyphen-separated lower case as opposed to camel case, otherwise, they are exactly the same. For example, Button is "button", RadioButton is "radio-button", Tooltip is "tooltip" and so on. If you wish to override an existing style in your stylesheet, you can do so simply by providing the rule you would like to use. For example, if you wanted all Buttons to be red by default, you could do the following:
If you wish to take complete control of the look of a Control from CSS, then instead of overriding properties you may instead want to give your Control a different styleClass and provide unique styles for it in CSS. For example:
The class documentation for each Control defines the default Skin regions which can be styled. For further information regarding the CSS capabilities provided with JavaFX, see the CSS Reference Guide. |
||||||||||||||||||||||||||||||||||||
| javafx.scene.effect |
Provides the set of classes for attaching graphical filter effects to JavaFX Scene Graph Nodes.
Provides the set of classes for attaching graphical filter effects to JavaFX Scene Graph Nodes. An effect is a graphical algorithm that produces an image, typically
as a modification of a source image.
An effect can be associated with a scene graph |
||||||||||||||||||||||||||||||||||||
| javafx.scene.effect.light |
Provides the set of classes for light source implementations needed for the Lighting effect.
Provides the set of classes for light source implementations needed for the Lighting effect. |
||||||||||||||||||||||||||||||||||||
| javafx.scene.image |
Provides the set of classes for loading and displaying images.
Provides the set of classes for loading and displaying images.
|
||||||||||||||||||||||||||||||||||||
| javafx.scene.input |
Provides the set of classes for mouse and keyboard input event handling.
Provides the set of classes for mouse and keyboard input event handling. |
||||||||||||||||||||||||||||||||||||
| javafx.scene.layout |
The JavaFX layout API provides a mechanism to establish the dynamic layout behavior of nodes in the scene graph.
The JavaFX layout API provides a mechanism to establish the dynamic layout behavior of nodes in the scene graph. While parts of an application's scene graph may have a static layout where the size and position of nodes is fixed, other parts will need to be laid out dynamically as the application executes. This is required in part because JavaFX is a cross-platform technology, which means that often the precise size of things (screen, fonts, etc) may vary across platforms and cannot be reliably determined until runtime. The other driver is that modern interfaces are highly dynamic (rotating screens, variable content, etc), so it's impossible for most applications to predict the exact size and location of visual elements over time, especially if the user can resize the screen or nodes within it. Therefore, layout often requires that the size and position of nodes be defined relative to aspects of the scene graph (scene size, node bounds, etc), often resulting in a complex set of dependencies, particularly in a large scene. These dependencies can be defined by using JavaFX's bind language feature, however, as the scene becomes complex, this approach becomes both unwieldy to program and inefficient to execute. So, the scene graph also supports a procedural layout mechanism that enables branches of the scene graph to be marked as 'needing layout' so that such dirty branches will be laid out in a single top-down procedural layout pass on the next pulse, just prior to rendering. This approach allows layout changes to be coalesced and processed just once, avoiding unnecessary interim layout calculations. This layout mechanism is driven automatically by the scene graph once the application creates and displays a Scene. An application typically only needs to declare the scene graph structure using appropriate node classes and the scene graph invokes layout at appropriate times. Laying out a SceneApplications create a scene graph by placing nodes in the If an application wishes to constrain the contents of the scene graph to fit
within the visual bounds of the scene, then it should use a container
at the root of the scene and bind the container's
This will also ensure that for desktop applications, where the user may
resize the stage/scene, that the contents will track those dynamic changes.
For desktop applications, there are two ways to establish the initial
size of a scene. First, the application may set the scene's
Note that for non-desktop applications (tv, mobile), the size of the
stage/scene may be fixed by the device and not configurable by the application.
Resizable vs. Non-Resizable NodesThe scene graph supports both resizable and non-resizable nodes. A resizable
node is one which has a range of acceptable sizes (minimum, preferred, maximum) and
its parent will resize it within that range during layout, given the parent's own layout
policy and the layout needs of sibling nodes. Applications should therefore not
set the
For example:
Note: Be aware that Rectangle's
Using Groups vs. ContainersGroup and Container are both general-purpose Parent classes, however each deals with layout differently. Group is not Resizable and does not constrain its
content in any way; it simply takes on the collective bounds of its children.
Groups do not position their children, so applications must set the position
of nodes inside a group. If a group contains Resizable content,
it will auto-size those nodes to their preferred sizes during layout, unless
Container classes are Resizable and are designed to perform layout on their children. They will attempt to constrain their contents to fit within their width/height, although it's possible for their content to extend outside their bounds and the container will not clip it. Containers will also layout children regardless of their visibility, so if an application doesn't want an invisible node to be factored into the container's layout, then it should unmanage it (described later). To compare with the Group example above, let's instead use an HBox container to create the same row of circles:
As the preceding example shows, it's much easier to use Container classes to achieve common layout patterns, so applications should utilize containers whenever possible and fall back to direct layout inside groups when containers won't suffice or the direct approach is sufficiently simple (e.g. static positioning or minimal bind requirements). If an application doesn't want a parent (Container, Group, etc) to manage the layout of a node at all, it can unmanage the node:
Once a node is unmanaged, the application must take full responsibility to
manage the size and position of the node, as its parent will completely
ignore it in terms of layout. See Node.managed
for more details.
Using Concrete ContainersThe platform provides a handful of concrete Container classes for common layout idioms:
Applications often need to nest different containers to achieve desired layout structure. For example, the following code creates a scene with an 8 pixel margin around the edges, a toolbar spanning the top, a tile of images in the center, and a status area at the bottom:
All of the concrete container classes do layout by assigning a "layout area" to each child and then laying out the child within that area using the child's layout preferences for sizing and alignment. If the child is Resizable (Controls and Containers), the container will use its sizing preferences to compute its layout area and determine how to size it within that area. If the child is non-resizable (Shapes, Group, etc), the container will treat it as a rigid object and simply position it within its layout area. Customizing Layout PreferencesAll the concrete container classes support customizing layout preferences on a per-node basis by setting a LayoutInfo on the node's layoutInfo variable. The most common application usage of LayoutInfo is to override the preferred size of a resizable node:
Understanding Layout BoundsNode defines a separate
So for example, if a DropShadow is added to a shape, that shadow will not be factored into the bounds of that shape for layout. Or, if a ScaleTransition is used to pulse the size of a button, that pulse animation will not disturb layout around that button. |
||||||||||||||||||||||||||||||||||||
| javafx.scene.media |
Provides the set of classes for integrating audio and video into JavaFX Applications.
Provides the set of classes for integrating audio and video into JavaFX Applications. Currently, the primarily used for this package is media playback. There are 3 essential classes in the Media Package: Media, MediaPlayer, and MediaView.
This is an example of a simple media player application:
The |
||||||||||||||||||||||||||||||||||||
| javafx.scene.paint |
Provides the set of classes for colors and gradients used to fill shapes and backgrounds when rendering the scene graph.
Provides the set of classes for colors and gradients used to fill shapes and backgrounds when rendering the scene graph. |
||||||||||||||||||||||||||||||||||||
| javafx.scene.shape |
Provides the set of 2D classes for defining and performing operations on objects related to two-dimensional geometry.
Provides the set of 2D classes for defining and performing operations on objects related to two-dimensional geometry. |
||||||||||||||||||||||||||||||||||||
| javafx.scene.text |
Provides the set of classes for fonts and renderable Text Node.
Provides the set of classes for fonts and renderable Text Node. |
||||||||||||||||||||||||||||||||||||
| javafx.scene.transform |
Provides the set of convenient classes to perform rotating, scaling,
shearing, and translation transformations for
Provides the set of convenient classes to perform rotating, scaling,
shearing, and translation transformations for |
||||||||||||||||||||||||||||||||||||
| javafx.stage |
Provides the top-level container classes for JavaFX scripts.
Provides the top-level container classes for JavaFX scripts. This package encapsulates the JavaFX graphical script surroundings for the Stage - Scene metaphor, with different capabilites available to the Stage depending on the underlying semantics of the runtime container. The JavaFX TM Stage interface provides
interfaces and classes for the environment and presentation of JavaFX
script instantiations. The stage presentation specifics for each
JavaFX runtime platform will allow a script to be presented on different
platforms with consistent functionality across each runtime. The main areas of functionality of
|
||||||||||||||||||||||||||||||||||||
| javafx.util |

