Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 6 of 6
ChangeListener<Number> cln;
cln = new ChangeListener<Number>()
{
@Override
public void changed(ObservableValue ov, Number oldval, Number newval)
{
fDirty = true;
}
};
ta.lengthProperty().addListener(cln);
Like JPad, JPadFX only enables the Edit menu's Cut and Copy menu items when the text area contains selected text. Unlike Swing, which uses a caret listener for this purpose, JavaFX accomplishes this task by registering a change listener with the text-area control's selected text property, as shown in Listing 9.
ChangeListener<String> cls;
cls = new ChangeListener<String>()
{
@Override
public void changed(ObservableValue ov,
String oldval,
String newval)
{
if (ta.getSelectedText().length() != 0)
{
miCopy.setDisable(false);
miCut.setDisable(false);
}
else
{
miCopy.setDisable(true);
miCut.setDisable(true);
}
}
};
ta.selectedTextProperty().addListener(cls);
Refactoring a Swing application to its JavaFX 2.0 equivalent involves migrating basic and advanced UI architectures. So far you've learned how JPadFX differs from its Swing JPad counterpart in terms of the use of a border pane for managing controls, menu system differences (including observable lists), the scene and stage, and event handling (including change listeners). In Part 3 we'll wrap up this tour of JPadFX by looking at how it interprets Swing JPad's original dialog boxes, clipboard, and drag-and-drop support.
Jeff Friesen is a freelance tutor and software developer with an emphasis on Java and Android. In addition to writing Java and Android books for Apress, Jeff has written numerous articles on Java and other technologies for JavaWorld, informIT, Java.net, and DevSource. Jeff can be contacted via his website at TutorTutor.ca.
Read more about Enterprise Java in JavaWorld's Enterprise Java section.
More from JavaWorld