|
import javafx.application.Application; |
|
import javafx.geometry.BoundingBox; |
|
import javafx.geometry.Bounds; |
|
import javafx.scene.Node; |
|
import javafx.scene.control.Button; |
|
import javafx.scene.control.ButtonType; |
|
import javafx.scene.control.Dialog; |
|
import javafx.scene.control.DialogPane; |
|
import javafx.scene.control.Label; |
|
import javafx.scene.control.TextArea; |
|
import javafx.scene.layout.FlowPane; |
|
import javafx.stage.Stage; |
|
import javafx.stage.WindowEvent; |
|
|
|
import java.util.ArrayList; |
|
import java.util.List; |
|
|
|
/** |
|
* Created by Dominik on 6/1/2015. |
|
*/ |
|
public class DialogButtonArea extends Application { |
|
|
|
private int missRadius = 10; |
|
|
|
@Override public void start(Stage primaryStage) throws Exception { |
|
final Dialog<ButtonType> dlg = new Dialog(); |
|
|
|
dlg.setTitle("TITLE"); |
|
|
|
Label label = new Label("LABEL"); |
|
label.setId("label"); |
|
TextArea textArea = new TextArea(); |
|
textArea.setId("textarea"); |
|
FlowPane pane = new FlowPane(); |
|
pane.getChildren().addAll(label, textArea); |
|
dlg.getDialogPane().setContent(pane); |
|
dlg.setResizable(false); |
|
|
|
final DialogPane dlgPane = dlg.getDialogPane(); |
|
|
|
dlgPane.getButtonTypes().add(ButtonType.OK); |
|
dlgPane.getButtonTypes().add(ButtonType.CANCEL); |
|
|
|
final Button btOk = (Button) dlg.getDialogPane() |
|
.lookupButton(ButtonType.OK); |
|
|
|
final Button btCancel = (Button) dlg.getDialogPane() |
|
.lookupButton(ButtonType.CANCEL); |
|
|
|
btOk.setId("okButton"); |
|
btCancel.setId("cancelButton"); |
|
|
|
List<Node> watchList = new ArrayList<Node>(); |
|
|
|
watchList.add(textArea); |
|
watchList.add(label); |
|
watchList.add(btCancel); |
|
watchList.add(btOk); |
|
|
|
// show dialog |
|
dlgPane.getScene().getWindow() |
|
.addEventHandler(WindowEvent.WINDOW_SHOWN, shown -> { |
|
System.out.println("Change"); |
|
dlgPane.getScene().getWindow() |
|
.addEventHandler(javafx.scene.input.MouseEvent.MOUSE_CLICKED, |
|
event -> { |
|
for (Node node : watchList) { |
|
Bounds thisBound = node |
|
.localToScene(node.getLayoutBounds()); |
|
Bounds thisBoundingBox = new BoundingBox( |
|
thisBound.getMinX() - missRadius, |
|
thisBound.getMinY() - missRadius, 0, |
|
thisBound.getWidth() + 2 * missRadius, |
|
thisBound.getHeight() + 2 * missRadius, 0); |
|
if (thisBoundingBox |
|
.contains(event.getSceneX(), event.getSceneY())) { |
|
System.out |
|
.println(node.getId() + " has been " + "missed."); |
|
} |
|
} |
|
}); |
|
}); |
|
dlg.showAndWait(); |
|
} |
|
} |