Example usage for javafx.scene.text Text Text

List of usage examples for javafx.scene.text Text Text

Introduction

In this page you can find the example usage for javafx.scene.text Text Text.

Prototype

public Text(String text) 

Source Link

Document

Creates an instance of Text containing the given string.

Usage

From source file:Main.java

  @Override
public void start(Stage stage) {
  Scene scene = new Scene(new HBox(20), 400, 100);
  HBox box = (HBox) scene.getRoot();/*  w  ww  . j  a va 2s  .co  m*/
  final ColorPicker colorPicker = new ColorPicker();
  colorPicker.setValue(Color.RED);

  final Text text = new Text("Color picker:");
  text.setFill(colorPicker.getValue());

  colorPicker.setOnAction((ActionEvent t) -> {
    text.setFill(colorPicker.getValue());
  });

  box.getChildren().addAll(colorPicker, text);

  stage.setScene(scene);
  stage.show();
}

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.
 * //from w  ww . java  2  s.c  o  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

private FlowPane createTopBanner() {
    FlowPane topBanner = new FlowPane();
    topBanner.setPrefHeight(40);//from w  w w  .  j a  v  a2  s  .  c o  m

    Font serif = Font.font("Dialog", 30);

    Text contactText = new Text("Contacts");
    contactText.setFill(Color.BLACK);
    contactText.setFont(serif);

    topBanner.getChildren().addAll(contactText);

    return topBanner;
}

From source file:com.github.drbookings.ui.controller.UpcomingController.java

private static void addCheckInNotes(final LocalDate date, final VBox box,
        final List<CheckInOutDetails> checkInNotes) {

    if (checkInNotes.size() > 0) {
        for (final CheckInOutDetails next : checkInNotes) {
            final TextFlow tf = new TextFlow();
            final Text t0 = new Text("Room " + next.room);
            t0.getStyleClass().add("emphasis");
            final Text t1 = new Text(" (" + next.bookingOrigin + ")");
            tf.getChildren().addAll(t0, t1);
            if (!StringUtils.isBlank(next.notes)) {
                final Text t2 = new Text(": " + next.notes);
                t2.getStyleClass().add("guest-message");
                tf.getChildren().add(t2);
            }/*from   w  ww  .ja v  a  2s . c o  m*/
            box.getChildren().add(tf);
        }
        box.getChildren().add(new Separator());
    }
}

From source file:org.pdfsam.ui.news.News.java

News(NewsData data) {
    this.getStyleClass().add("news-box");
    TextFlow flow = new TextFlow();
    if (data.isImportant()) {
        Text megaphone = GlyphsDude.createIcon(FontAwesomeIcon.BULLHORN, "1.2em");
        megaphone.getStyleClass().clear();
        megaphone.getStyleClass().add("news-box-title-important");
        flow.getChildren().addAll(megaphone, new Text(" "));
    }// w w  w  .j a  v a2  s  .c om

    Text titleText = new Text(data.getTitle() + System.lineSeparator());
    titleText.setOnMouseClicked(e -> eventStudio().broadcast(new OpenUrlRequest(data.getLink())));
    titleText.getStyleClass().add("news-box-title");

    Text contentText = new Text(data.getContent());
    contentText.setTextAlignment(TextAlignment.JUSTIFY);
    contentText.getStyleClass().add("news-content");

    flow.getChildren().addAll(titleText, contentText);
    flow.setTextAlignment(TextAlignment.JUSTIFY);
    Label labelDate = new Label(FORMATTER.format(data.getDate()),
            GlyphsDude.createIcon(MaterialDesignIcon.CLOCK));
    labelDate.setPrefWidth(Integer.MAX_VALUE);
    HBox.setHgrow(labelDate, Priority.ALWAYS);
    HBox bottom = new HBox(labelDate);
    bottom.setAlignment(Pos.CENTER_LEFT);
    bottom.getStyleClass().add("news-box-footer");
    if (isNotBlank(data.getLink())) {
        Button link = UrlButton.urlButton(null, data.getLink(), FontAwesomeIcon.EXTERNAL_LINK_SQUARE,
                "pdfsam-toolbar-button");
        bottom.getChildren().add(link);
    }
    getChildren().addAll(flow, bottom);
}

From source file:com.github.drbookings.LocalDates.java

public static TextFlow getYearText(final LocalDate date) {
    final TextFlow tf = new TextFlow();
    final Text t0 = new Text(getYearString(date));
    t0.getStyleClass().add("center-text");
    tf.getChildren().addAll(t0);//from   w ww .java 2 s  .co m
    return tf;
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("JavaFX Welcome");
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);//from   w w  w  . j a v  a  2 s. com
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));

    Text scenetitle = new Text("Welcome");
    scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
    grid.add(scenetitle, 0, 0, 2, 1);

    Label userName = new Label("User Name:");
    grid.add(userName, 0, 1);

    TextField userTextField = new TextField();
    grid.add(userTextField, 1, 1);

    Label pw = new Label("Password:");
    grid.add(pw, 0, 2);

    PasswordField pwBox = new PasswordField();
    grid.add(pwBox, 1, 2);

    Button btn = new Button("Sign in");
    HBox hbBtn = new HBox(10);
    hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
    hbBtn.getChildren().add(btn);
    grid.add(hbBtn, 1, 4);

    final Text actiontarget = new Text();
    grid.add(actiontarget, 1, 6);

    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {
            actiontarget.setFill(Color.FIREBRICK);
            actiontarget.setText("Sign in button pressed");
        }
    });

    Scene scene = new Scene(grid, 300, 275);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:FeeBooster.java

@Override
public void start(Stage primaryStage) throws Exception {

    // Setup the stage
    stage = primaryStage;/*from w w w  . ja va 2 s  . com*/
    primaryStage.setTitle("Bitcoin Transaction Fee Booster");

    // Setup intro gridpane
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));

    // Intro Text
    Text scenetitle = new Text(
            "Welcome to the fee booster. \n\nWhat type of transaction would you like to boost the fee of?");
    grid.add(scenetitle, 0, 0, 2, 3);

    // radio button selections
    VBox boostRadioVbox = new VBox();
    ToggleGroup boostTypeGroup = new ToggleGroup();
    RadioButton rbfRadio = new RadioButton("A transaction you sent");
    rbfRadio.setToggleGroup(boostTypeGroup);
    boostRadioVbox.getChildren().add(rbfRadio);
    RadioButton cpfpRadio = new RadioButton("A transaction you received");
    cpfpRadio.setToggleGroup(boostTypeGroup);
    rbfRadio.setSelected(true);
    boostRadioVbox.getChildren().add(cpfpRadio);
    grid.add(boostRadioVbox, 0, 3);

    // Instructions Text
    Text instruct = new Text("Please enter the raw hex or transaction id of your transaction below:");
    grid.add(instruct, 0, 4);

    // Textbox for hex of transaction
    TextArea txHexTxt = new TextArea();
    txHexTxt.setWrapText(true);
    grid.add(txHexTxt, 0, 5, 5, 1);

    // Next Button
    Button nextBtn = new Button("Next");
    nextBtn.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {

            // Create Transaction
            Transaction tx = new Transaction();

            // Check if txid
            boolean isTxid = txHexTxt.getText().length() == 64 && txHexTxt.getText().matches("[0-9A-Fa-f]+");
            if (isTxid)
                tx.setHash(txHexTxt.getText());

            // Determine which page to go to
            if (Transaction.deserializeStr(txHexTxt.getText(), tx) || isTxid) {

                // Get the fee
                JSONObject apiResult = Utils
                        .getFromAnAPI("https://api.blockcypher.com/v1/btc/main/txs/" + tx.getHash(), "GET");

                // Get the fee
                tx.setFee(apiResult.getInt("fees"));
                tx.setTotalAmtPre(tx.getFee() + tx.getOutAmt());

                // Get info if txid
                if (isTxid) {

                }

                Scene scene = null;
                if (rbfRadio.isSelected())
                    if (sceneCursor == scenes.size() - 1 || !rbf) {
                        scene = new Scene(rbfGrid(tx), 900, 500);
                        if (!rbf) {
                            scenes.clear();
                            scenes.add(stage.getScene());
                        }
                        rbf = true;
                    }
                if (cpfpRadio.isSelected())
                    if (sceneCursor == scenes.size() - 1 || rbf) {
                        scene = new Scene(cpfpGrid(tx), 900, 500);
                        if (rbf) {
                            scenes.clear();
                            scenes.add(stage.getScene());
                        }
                        rbf = false;
                    }

                if (sceneCursor != scenes.size() - 1)
                    scene = scenes.get(sceneCursor + 1);
                else
                    scenes.add(scene);
                sceneCursor++;
                stage.setScene(scene);
            } else {
                Alert alert = new Alert(Alert.AlertType.ERROR, "Please enter a valid transaction");
                alert.showAndWait();
            }
        }
    });
    HBox btnHbox = new HBox(10);
    btnHbox.getChildren().add(nextBtn);

    // Cancel Button
    Button cancelBtn = new Button("Cancel");
    cancelBtn.setOnAction(cancelEvent);
    btnHbox.getChildren().add(cancelBtn);
    grid.add(btnHbox, 2, 7);

    // Display everything
    Scene scene = new Scene(grid, 900, 500);
    scenes.add(scene);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:com.github.drbookings.ui.controller.UpcomingController.java

private static void addCheckInSummary(final LocalDate date, final VBox box,
        final List<CheckInOutDetails> checkInNotes) {
    final TextFlow tf = new TextFlow();
    if (checkInNotes.size() > 0) {
        final Text t1 = new Text(checkInNotes.size() + " ");
        t1.getStyleClass().add("emphasis");
        t1.getStyleClass().add("copyable-label");
        final Text t2;
        if (checkInNotes.size() > 1) {
            t2 = new Text("check-ins,");
        } else {/*  w  ww . j  a  v  a 2s.  c o  m*/
            t2 = new Text("check-in,");
        }
        t2.getStyleClass().add("emphasis");
        tf.getStyleClass().add("copyable-label");
        tf.getChildren().addAll(t1, t2);
    }

    if (checkInNotes.isEmpty()) {
        // tf.getChildren().add(new Text("no check-ins,"));
    }
    box.getChildren().add(tf);
}

From source file:org.mskcc.shenkers.control.alignment.VerticalOverlayNGTest.java

@Override
public void start(Stage stage) throws Exception {
    Pane r1 = new Pane();
    Text lbl = new Text("H");

    List<Node> collect = "ABcDEFGHIJKL".chars().mapToObj(new IntFunction<StretchStringPane>() {

        @Override/*from  www. ja  v  a  2 s .  c  om*/
        public StretchStringPane apply(int value) {
            return new StretchStringPane("" + ((char) value));
        }
    }).collect(Collectors.toList());

    VerticalOverlay ao = new VerticalOverlay();
    ao.setChildren(collect);
    ao.flip();

    Scene scene = new Scene(ao.getContent(), 300, 300, Color.GRAY);
    stage.setTitle("JavaFX Scene Graph Demo");
    stage.setScene(scene);
    stage.show();
}