List of usage examples for javafx.scene.control Button setText
public final void setText(String value)
From source file:TwoButtons.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); final RowLayout layout = new RowLayout(); shell.setLayout(layout);// w ww.j a va 2 s .com /* Create the SWT button */ final org.eclipse.swt.widgets.Button swtButton = new org.eclipse.swt.widgets.Button(shell, SWT.PUSH); swtButton.setText("SWT Button"); /* Create an FXCanvas */ final FXCanvas fxCanvas = new FXCanvas(shell, SWT.NONE) { public Point computeSize(int wHint, int hHint, boolean changed) { getScene().getWindow().sizeToScene(); int width = (int) getScene().getWidth(); int height = (int) getScene().getHeight(); return new Point(width, height); } }; /* Create a JavaFX Group node */ Group group = new Group(); /* Create a JavaFX button */ final Button jfxButton = new Button("JFX Button"); /* Assign the CSS ID ipad-dark-grey */ jfxButton.setId("ipad-dark-grey"); /* Add the button as a child of the Group node */ group.getChildren().add(jfxButton); /* Create the Scene instance and set the group node as root */ Scene scene = new Scene(group, Color.rgb(shell.getBackground().getRed(), shell.getBackground().getGreen(), shell.getBackground().getBlue())); /* Attach an external stylesheet */ scene.getStylesheets().add("twobuttons/Buttons.css"); fxCanvas.setScene(scene); /* Add Listeners */ swtButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { jfxButton.setText("JFX Button: Hello from SWT"); shell.layout(); } }); jfxButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { swtButton.setText("SWT Button: Hello from JFX"); shell.layout(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:nl.mvdr.umvc3replayanalyser.gui.ErrorMessagePopup.java
/** * Handles an exception that caused program startup to fail, by showing an error message to the user. * /* w w w .ja v a 2 s .co m*/ * @param title * title for the dialog * @param errorMessage * error message * @param stage * stage in which to show the error message * @param exception * exception that caused the error */ public static void show(String title, String errorMessage, final Stage stage, Exception exception) { log.info("Showing error message dialog to indicate that startup failed."); // Create the error dialog programatically without relying on FXML, to minimize the chances of further failure. stage.setTitle(title); // Error message text. Text text = new Text(errorMessage); // Text area containing the stack trace. Not visible by default. String stackTrace; if (exception != null) { stackTrace = ExceptionUtils.getStackTrace(exception); } else { stackTrace = "No more details available."; } final TextArea stackTraceArea = new TextArea(stackTrace); stackTraceArea.setEditable(false); stackTraceArea.setVisible(false); // Details button for displaying the stack trace. Button detailsButton = new Button(); detailsButton.setText("Details"); detailsButton.setOnAction(new EventHandler<ActionEvent>() { /** {@inheritDoc} */ @Override public void handle(ActionEvent event) { log.info("User clicked Details."); stackTraceArea.setVisible(!stackTraceArea.isVisible()); } }); // OK button for closing the dialog. Button okButton = new Button(); okButton.setText("OK"); okButton.setOnAction(new EventHandler<ActionEvent>() { /** {@inheritDoc} */ @Override public void handle(ActionEvent event) { log.info("User clicked OK, closing the dialog."); stage.close(); } }); // Horizontal box containing the buttons, to make sure they are always centered. HBox buttonsBox = new HBox(5); buttonsBox.getChildren().add(detailsButton); buttonsBox.getChildren().add(okButton); buttonsBox.setAlignment(Pos.CENTER); // Layout constraints. AnchorPane.setTopAnchor(text, Double.valueOf(5)); AnchorPane.setLeftAnchor(text, Double.valueOf(5)); AnchorPane.setRightAnchor(text, Double.valueOf(5)); AnchorPane.setTopAnchor(stackTraceArea, Double.valueOf(31)); AnchorPane.setLeftAnchor(stackTraceArea, Double.valueOf(5)); AnchorPane.setRightAnchor(stackTraceArea, Double.valueOf(5)); AnchorPane.setBottomAnchor(stackTraceArea, Double.valueOf(36)); AnchorPane.setLeftAnchor(buttonsBox, Double.valueOf(5)); AnchorPane.setRightAnchor(buttonsBox, Double.valueOf(5)); AnchorPane.setBottomAnchor(buttonsBox, Double.valueOf(5)); AnchorPane root = new AnchorPane(); root.getChildren().addAll(text, stackTraceArea, buttonsBox); stage.setScene(new Scene(root)); // Use a standard program icon if possible. try { stage.getIcons().add(Icons.get().getRandomPortrait()); } catch (IllegalStateException e) { log.warn("Failed to load icon for error dialog; proceeding with default JavaFX icon.", e); } stage.show(); // Default size should also be the minimum size. stage.setMinWidth(stage.getWidth()); stage.setMinHeight(stage.getHeight()); log.info("Error dialog displayed."); }
From source file:Main.java
@Override public void start(Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 300, 250); Button btn = new Button(); btn.setText("Hello World"); btn.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { System.out.println("Hello World"); }//w w w . j a v a2 s . c om }); root.getChildren().add(btn); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("Hello World!"); Button btn = new Button(); btn.setText("Say 'Hello World'"); btn.setOnAction(new EventHandler<ActionEvent>() { @Override//w w w .j a v a 2s .c om public void handle(ActionEvent event) { System.out.println("Hello World!"); } }); StackPane root = new StackPane(); root.getChildren().add(btn); primaryStage.setScene(new Scene(root, 300, 250)); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { Button btn = new Button(); btn.setText("Say 'Hello World'"); btn.setOnAction(new EventHandler<ActionEvent>() { @Override// w w w .ja v a 2 s . c o m public void handle(ActionEvent event) { System.out.println("Hello World!"); } }); StackPane root = new StackPane(); root.getChildren().add(btn); Scene scene = new Scene(root, 300, 250); primaryStage.setTitle("Hello World!"); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 300, 250); Button btn = new Button(); btn.setText("Hello World"); btn.setOnMouseEntered(new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { System.out.println("Mouse entered"); }//from w ww. jav a2s .c o m }); btn.setOnMouseExited(new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { System.out.println("Mouse exited"); } }); btn.setOnMousePressed(new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { System.out.println("Mouse pressed"); } }); root.getChildren().add(btn); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("HBox Test"); // HBox/*from w ww.j a v a 2 s .c om*/ HBox hb = new HBox(); hb.setPadding(new Insets(15, 12, 15, 12)); hb.setSpacing(10); // Buttons Button btn1 = new Button(); btn1.setText("Button1"); hb.getChildren().add(btn1); Button btn2 = new Button(); btn2.setText("Button2"); hb.getChildren().add(btn2); Button btn3 = new Button(); btn3.setText("Button3"); hb.getChildren().add(btn3); Button btn4 = new Button(); btn4.setText("Button4"); hb.getChildren().add(btn4); // Adding HBox to the scene Scene scene = new Scene(hb); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("VBox Test"); VBox vb = new VBox(); vb.setPadding(new Insets(10, 50, 50, 50)); vb.setSpacing(10);// w ww. jav a 2s . c o m Label lbl = new Label("VBox"); lbl.setFont(Font.font("Amble CN", FontWeight.BOLD, 24)); vb.getChildren().add(lbl); Button btn1 = new Button(); btn1.setText("Button1"); vb.getChildren().add(btn1); Button btn2 = new Button(); btn2.setText("Button2"); vb.getChildren().add(btn2); Button btn3 = new Button(); btn3.setText("Button3"); vb.getChildren().add(btn3); Button btn4 = new Button(); btn4.setText("Button4"); vb.getChildren().add(btn4); // Adding VBox to the scene Scene scene = new Scene(vb); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("VBox Test"); // VBox/*from w w w . j a v a 2 s. co m*/ VBox vb = new VBox(); vb.setPadding(new Insets(10, 50, 50, 50)); vb.setSpacing(10); Label lbl = new Label("VBox"); lbl.setFont(Font.font("Amble CN", FontWeight.BOLD, 24)); vb.getChildren().add(lbl); // Buttons Button btn1 = new Button(); btn1.setText("Button1"); vb.getChildren().add(btn1); Button btn2 = new Button(); btn2.setText("Button2"); vb.getChildren().add(btn2); Button btn3 = new Button(); btn3.setText("Button3"); vb.getChildren().add(btn3); Button btn4 = new Button(); btn4.setText("Button4"); vb.getChildren().add(btn4); // Adding VBox to the scene Scene scene = new Scene(vb); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("VBox Test"); VBox vb = new VBox(); vb.setPadding(new Insets(10, 50, 50, 50)); vb.setSpacing(10);/*from w w w . j av a 2 s . c o m*/ vb.setFillWidth(true); System.out.println(vb.spacingProperty()); Label lbl = new Label("VBox"); lbl.setFont(Font.font("Amble CN", FontWeight.BOLD, 24)); vb.getChildren().add(lbl); Button btn1 = new Button(); btn1.setText("Button1"); vb.getChildren().add(btn1); Button btn2 = new Button(); btn2.setText("Button2"); vb.getChildren().add(btn2); Button btn3 = new Button(); btn3.setText("Button3"); vb.getChildren().add(btn3); Button btn4 = new Button(); btn4.setText("Button4"); vb.getChildren().add(btn4); // Adding VBox to the scene Scene scene = new Scene(vb); primaryStage.setScene(scene); primaryStage.show(); }