Introduccion A Fxml

Páginas: 19 (4678 palabras) Publicado: 22 de febrero de 2013
Introducing FXML
A Markup Language for JavaFX Greg Brown, 8/15/2011 FXML is a scriptable, XML-based markup language for constructing Java object graphs. It provides a convenient alternative to constructing such graphs in procedural code, and is ideally suited to defining the user interface of a JavaFX application, since the hierarchical structure of an XML document closely parallels the structureof the JavaFX scene graph. This document introduces the FXML markup language and explains how it can be used to simplify development of JavaFX applications.

Elements
In FXML, an XML element represents one of the following: • A class instance • A property of a class instance • A "static" property • A "define" block • A block of script code Class instances, instance properties, staticproperties, and define blocks are discussed in this section below. Scripting is discussed in a later section.

Value Elements
Class instances can be constructed in FXML in several ways. The most common is via instance declaration elements, which simply create a new instance of a class by name. Other ways of creating class instances include referencing existing values, copying existing values, andincluding external FXML files. Each is discussed in more detail below. Instance Declarations If an element's tag name begins with an uppercase letter (and it is not a "static" property setter, described later), it is considered an instance declaration. When the FXML loader (also introduced later) encounters such an element, it creates an instance of that class. As in Java, class names can be fully-qualified(including the package name), or they can be imported using the "import" processing instruction (PI). For example, the following PI imports the javafx.scene.control.Label class into the current FXML documentʼs namespace:


This PI imports all classes from the javafx.scene.control package into the current namespace:


Any class that adheres to JavaBean constructor and property namingconventions can be readily instantiated and configured using FXML. The following is a simple but complete example that creates an instance of javafx.scene.control.Label and sets its "text" property to "Hello, World!":
1



Note that the Labelʼs "text" property in this example is set using an XML attribute. Properties can also be set using nested property elements. Property elements are discussed inmore detail later in this section. Property attributes are discussed in a later section. Classes that don't conform to Bean conventions can also be constructed in FXML, using an object called a "builder". Builders are discussed in more detail later.
Maps

Internally, the FXML loader uses an instance of com.sun.javafx.fxml.BeanAdapter to wrap an instantiated object and invoke its settermethods. This (currently) private class implements the java.util.Map interface and allows a caller to get and set Bean property values as key/value pairs. If an element represents a type that already implements Map (such as java.util.HashMap), it is not wrapped and its get() and put() methods are invoked directly. For example, the following FXML creates an instance of HashMap and sets its "foo" and "bar"values to "123" and "456", respectively:


fx:value The fx:value attribute can be used to initialize an instance of a type that does not have a default constructor but provides a static valueOf(String) method. For example, java.lang.String as well as each of the primitive wrapper types define a valueOf() method and can be constructed in

FXML as follows:


Custom classes that define astatic valueOf(String) method can also be constructed this way.
fx:factory The fx:factory attribute is another means of creating objects whose classes do not have a default

constructor. The value of the attribute is the name of a static, no-arg factory method for producing class instances. For example, the following markup creates an instance of an observable array list, populated with three...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Introduccion
  • Introduccion
  • Introduccion
  • Introduccion
  • Introduccion
  • introduccion
  • Introduccion
  • INTRODUCCION

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS