Example usage for javafx.scene.control Label Label

List of usage examples for javafx.scene.control Label Label

Introduction

In this page you can find the example usage for javafx.scene.control Label Label.

Prototype

public Label(String text) 

Source Link

Document

Creates Label with supplied text.

Usage

From source file:Main.java

public static Label createLabel(String label, String cssClass, Pane parent) {
    Label l = new Label(label);
    l.getStyleClass().add("label-defaults");
    l.getStyleClass().add(cssClass);// ww  w. j a v  a 2 s .  c  o  m
    parent.getChildren().add(l);
    return l;
}

From source file:Main.java

public static Label createCustomLabel(String label, String cssClass, Pane parent) {
    Label l = new Label(label);
    l.getStyleClass().add(cssClass);// w  w w  .j  a  v  a2s .com
    parent.getChildren().add(l);
    return l;
}

From source file:Main.java

/**
 * Creates a popup containing error without any pretty things for a graphical way to show errors
 * @param error Error string to show//ww  w . j  a  va2s. c o m
 */
public static void showError(String error) {
    if (Platform.isFxApplicationThread()) {
        Stage s = new Stage();
        VBox v = new VBox();
        v.getChildren().add(new Label("Error [" + error + ']'));
        Scene sc = new Scene(v);
        s.setTitle("Fail");
        s.setScene(sc);
        s.show();
    } else {
        Platform.runLater(() -> {
            Stage s = new Stage();
            VBox v = new VBox();
            v.getChildren().add(new Label("Error [" + error + ']'));
            Scene sc = new Scene(v);
            s.setTitle("Fail");
            s.setScene(sc);
            s.show();
        });
    }
}

From source file:de.pixida.logtest.designer.commons.ExceptionDialog.java

public static void showFatalException(final String title, final String message, final Throwable exception) {
    final Alert alert = new Alert(Alert.AlertType.ERROR);
    alert.initStyle(StageStyle.UTILITY);
    alert.setTitle("Error");
    alert.setHeaderText(title);/*  w  w  w.  ja v a 2s.c  o  m*/
    alert.setContentText(message);

    final Label label = new Label("Details:");

    final TextArea textArea = new TextArea(ExceptionUtils.getStackTrace(exception));
    textArea.setEditable(false);
    textArea.setWrapText(true);

    textArea.setMaxWidth(Double.MAX_VALUE);
    textArea.setMaxHeight(Double.MAX_VALUE);
    GridPane.setVgrow(textArea, Priority.ALWAYS);
    GridPane.setHgrow(textArea, Priority.ALWAYS);

    final GridPane expContent = new GridPane();
    expContent.setMaxWidth(Double.MAX_VALUE);
    expContent.add(label, 0, 0);
    expContent.add(textArea, 0, 1);

    alert.getDialogPane().setExpandableContent(expContent);

    alert.showAndWait();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Label msg = new Label("java2s.com");
    msg.setStyle("-fx-text-fill: blue;");

    VBox root = new VBox();
    root.getChildren().add(msg);/*from w  w  w.java  2s.  c o m*/

    Scene scene = new Scene(root, 300, 50);
    stage.setScene(scene);
    stage.setTitle("Hello JavaFX Application with a Scene");
    stage.show();
}

From source file:Main.java

public static void executeWithProgressDialogInBackground(final Runnable runnable, final StackPane target,
        final String text) {
    Thread th = new Thread() {
        @Override//  www .  j  a v  a2  s  .  c  o  m
        public void run() {
            final Node progressIndicator = createProgressIndicator();
            final Label label = new Label(text);
            try {
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        target.getChildren().add(progressIndicator);
                        label.setWrapText(true);
                        target.getChildren().add(label);
                    }
                });
                runnable.run();
            } finally {
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        target.getChildren().remove(progressIndicator);
                        target.getChildren().remove(label);
                    }
                });
            }
        }
    };
    th.setDaemon(true);
    th.start();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Group group = new Group();
    Scene scene = new Scene(group);

    Label title = new Label("Label 1");
    StackPane stackpane = new StackPane();
    StackPane.setAlignment(title, Pos.BOTTOM_CENTER);
    stackpane.getChildren().addAll(new Label("Label"), title);

    group.getChildren().add(stackpane);/*from w w  w.j a v a 2s.  c o m*/

    stage.setTitle("Welcome to JavaFX!");
    stage.setScene(scene);
    stage.sizeToScene();
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    TextField fNameFld = new TextField();
    Label fNameLbl = new Label("First Name:");

    TextField lNameFld = new TextField();
    Label lNameLbl = new Label("Last Name:");

    GridPane root = new GridPane();
    root.addRow(0, fNameLbl, fNameFld);//  w ww  .  ja v  a 2  s . c o m
    root.addRow(1, lNameLbl, lNameFld);

    // Set a CSS for the GridPane
    root.setStyle("-fx-padding: 10;" + "-fx-border-style: solid inside;" + "-fx-border-width: 2;"
            + "-fx-border-insets: 5;" + "-fx-border-radius: 5;" + "-fx-border-color: blue;");

    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Label nameLbl = new Label("Enter your name:");
    TextField nameFld = new TextField();

    Label msg = new Label();

    Button sayHelloBtn = new Button("Say Hello");

    sayHelloBtn.setOnAction(e -> {//from   w w  w . j a va2s  .co  m
        String name = nameFld.getText();
        if (name.trim().length() > 0) {
            msg.setText("Hello " + name);
        } else {
            msg.setText("Hello there");
        }
    });

    VBox root = new VBox();

    root.setSpacing(5);

    root.getChildren().addAll(nameLbl, nameFld, msg, sayHelloBtn);

    Scene scene = new Scene(root, 350, 150);
    stage.setScene(scene);
    stage.setTitle("hi");
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Label nameLbl = new Label("Enter your name:");
    TextField nameFld = new TextField();

    Label msg = new Label();
    msg.setStyle("-fx-text-fill: blue;");

    Button sayHelloBtn = new Button("Say Hello");
    Button exitBtn = new Button("Exit");

    sayHelloBtn.setOnAction(e -> {//from  www.j av  a 2s .  c  om
        String name = nameFld.getText();
        if (name.trim().length() > 0) {
            msg.setText("Hello " + name);
        } else {
            msg.setText("Hello there");
        }
    });

    exitBtn.setOnAction(e -> Platform.exit());

    VBox root = new VBox();

    root.setSpacing(5);
    root.getChildren().addAll(nameLbl, nameFld, msg, sayHelloBtn, exitBtn);

    Scene scene = new Scene(root, 350, 150);
    stage.setScene(scene);
    stage.show();
}