|
|
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 4 of 6
setPrefWidth(60.0) call on each button sets the button's preferred width to 60.0. This ensures that both buttons have the same width, which
improves the dialog box's aesthetics.
javafx.scene.layout.HBoxBuilder class is used to create a javax.scene.layout.HBox instance that horizontally lays out the Yes and No buttons. This container is then added to the VBox instance returned from VBoxBuilder.build() to ensure a nice-looking UI.
FileChooser is concerned (FileChooser delegates to the underlying platform's native file chooser), it permits the JavaFX application thread to continue executing
code that follows a call to show a modal stage. We have to proceed with caution when handling the modal dialog box, lest we
face unintended consequences.
If a user attempted to close the primary stage immediately after showing a modal child stage then the child stage would never
be displayed, because the JavaFX thread would execute the close code immediately after executing the code that shows the modal
child stage. To address this behavior, we can introduce a pair of fields and methods into AreYouSure that let the application assign separate event handlers to the Yes and No buttons. When the user presses Yes, the Yes button's
event handler executes. Similarly, the No button's event handler executes when the user presses No. This way, no UI code need
follow the call to show the AreYouSure dialog box. The appropriate code will execute via the handler assigned to Yes or No,
as shown in Listing 6.
EventHandler<ActionEvent> ehae;
ehae = new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent ae)
{
if (fDirty)
{
AreYouSure ays = new AreYouSure(stage, SAVE_CHNGS);
EventHandler<ActionEvent> ehae1;
ehae1 = new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent ae)
{
if (doSave())
doNew();
}
};
ays.setOnYes(ehae1);
EventHandler<ActionEvent> ehae2;
ehae2 = new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent ae)
{
doNew();
}
};
ays.setOnNo(ehae2);
ays.show();
// There should be no UI code here.
}
else
doNew();
}
};
miNew.setOnAction(ehae);
Figure 3 shows the AreYouSure dialog box.

JPadFX supports system clipboard access via cut, copy, and paste operations. Much of this support is handled automatically
by TextArea, which accesses the system clipboard and performs a cut, copy, or paste operation when it detects a specific key combination,
such as Ctrl+C.
TextArea also inherits methods from its javafx.scene.control.TextInputControl superclass to programmatically access the system clipboard; void copy() is one example. Action-event handlers for JPadFX Edit menu items Cut, Copy, and Paste execute appropriate methods (such as
ta.copy();) when an item is selected.
More from JavaWorld