Java Code Examples for javafx.scene.control.Dialog#setGraphic()
The following examples show how to use
javafx.scene.control.Dialog#setGraphic() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiplayerClient.java From mars-sim with GNU General Public License v3.0 | 4 votes |
public void connectDialog() { // Create the custom dialog. Dialog<String> dialog = new Dialog<>(); // Get the Stage. Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow(); /* stage.setOnCloseRequest(e -> { boolean isExit = mainMenu.exitDialog(stage);//.getScreensSwitcher().exitDialog(stage); if (!isExit) { e.consume(); } else { Platform.exit(); } }); */ // Add corner icon. stage.getIcons().add(new Image(this.getClass().getResource("/icons/network/client48.png").toString())); // Add Stage icon dialog.setGraphic(new ImageView(this.getClass().getResource("/icons/network/network256.png").toString())); // dialog.initOwner(mainMenu.getStage()); dialog.setTitle("Mars Simulation Project"); dialog.setHeaderText("Multiplayer Client"); dialog.setContentText("Enter the host address : "); // Set the button types. ButtonType connectButtonType = new ButtonType("Connect", ButtonData.OK_DONE); // ButtonType localHostButton = new ButtonType("localhost"); // dialog.getDialogPane().getButtonTypes().addAll(localHostButton, // loginButtonType, ButtonType.CANCEL); dialog.getDialogPane().getButtonTypes().addAll(connectButtonType, ButtonType.CANCEL); // Create the username and password labels and fields. GridPane grid = new GridPane(); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(20, 150, 10, 10)); // TextField tfUser = new TextField(); // tfUser.setPromptText("Username"); TextField tfServerAddress = new TextField(); // PasswordField password = new PasswordField(); tfServerAddress.setPromptText("192.168.xxx.xxx"); tfServerAddress.setText("192.168.xxx.xxx"); Button localhostB = new Button("Use localhost"); // grid.add(new Label("Username:"), 0, 0); // grid.add(tfUser, 1, 0); grid.add(new Label("Server Address:"), 0, 1); grid.add(tfServerAddress, 1, 1); grid.add(localhostB, 2, 1); // Enable/Disable connect button depending on whether the host address // was entered. Node connectButton = dialog.getDialogPane().lookupButton(connectButtonType); connectButton.setDisable(true); // Do some validation (using the Java 8 lambda syntax). tfServerAddress.textProperty().addListener((observable, oldValue, newValue) -> { connectButton.setDisable(newValue.trim().isEmpty()); } ); dialog.getDialogPane().setContent(grid); // Request focus on the username field by default. Platform.runLater(() -> tfServerAddress.requestFocus()); // Convert the result to a username-password-pair when the login button // is clicked. dialog.setResultConverter(dialogButton -> { if (dialogButton == connectButtonType) { return tfServerAddress.getText(); } return null; } ); localhostB.setOnAction(event -> { tfServerAddress.setText("127.0.0.1"); } ); // localhostB.setPadding(new Insets(1)); // localhostB.setPrefWidth(10); Optional<String> result = dialog.showAndWait(); result.ifPresent(input -> { String serverAddressStr = tfServerAddress.getText(); this.serverAddressStr = serverAddressStr; logger.info("Connecting to server at " + serverAddressStr); loginDialog(); } ); }