Java Reference
In-Depth Information
...
textArea.addPropertyChangeListener(
PropertyChangeListener {
public override function propertyChange(
rev:PropertyChangeEvent) : Void {
if(inChange) {
return;
}
var property = ev.getPropertyName();
if(property == "text") {
text = textArea.getText();
...
...
This pattern can be repeated for any other Java attributes to JavaFX instance vari-
able mappings.
In Chapter 12, JavaFX Code Recipes, we will discuss this pattern in more detail .
You may have realized that a JTextField is usually shown in a JScrollPane
because the number of rows and columns may be more than the screen can accom-
modate; so we add one last tweak to our example. Instead of directly extending
javafx.ext.swing.SwingComponent , we extend javafx.ext.swing.Swing-
ScrollableComponent .
public class TextArea extends SwingScrollableComponent {
That's it! Now, we have scroll bar support.
To use our text area class, just use an object literal just like any other JavaFX
node.
Stage {
title: "TextArea custom component"
width: 475
height: 425
scene: Scene {
content: TextArea {
text: "Enter data here!"
columns: 40
rows: 24
lineWrap: true
wrapStyleWord: true
}
}
}
The full example is on the topic's Web site, http://www.jfxbook.com.
Search WWH ::




Custom Search