Example usage for javafx.scene.control Label setStyle

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

Introduction

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

Prototype

public final void setStyle(String value) 

Source Link

Document

A string representation of the CSS style associated with this specific Node .

Usage

From source file:main.TestManager.java

/**
 * Displays given test. Intended for testing and
 * evaluating correct answers. (student mode only)
 * @param test test to display// ww  w  .j  ava 2s.co  m
 * @param stage 
 */
public static void displayTest(Test test, Stage stage) {
    Debugger.println(test.getName() + " - is displayed.");
    TabPane tabPane = new TabPane();
    int counter = 1;
    for (Question q : test.getQuestions()) {
        Label instruction = new Label(q.question);
        instruction.setStyle("-fx-font-size: 20");
        Pane choices = q.getPaneOfChoices();
        VBox vbox = new VBox(instruction, choices);
        vbox.setSpacing(10);
        Tab tab = new Tab("Otzka " + Integer.toString(counter), vbox);
        tab.setStyle("-fx-font-size: 20");
        tabPane.getTabs().add(tab);
        counter++;
    }

    Button finish = new Button("Ukon?i test!");
    finish.setStyle("-fx-font-size: 20");
    finish.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            try {
                test.evaluate(stage);
            } catch (IOException e) {
                Alert alert = new Alert(AlertType.ERROR);
                alert.setContentText("Ojoj, vyskytol sa problm. Aplikcia sa mus ukon?i.");
                alert.showAndWait();
                System.exit(0);
            }
        }
    });
    Button nextQuestion = new Button("alia");
    nextQuestion.setStyle("-fx-font-size: 20");
    nextQuestion.setOnAction(e -> tabPane.getSelectionModel().selectNext());
    HBox buttons = new HBox(finish, nextQuestion);
    buttons.setSpacing(10);
    buttons.setAlignment(Pos.BOTTOM_CENTER);
    VBox outerVBox = new VBox(tabPane, buttons);
    outerVBox.setPadding(new Insets(10, 10, 10, 10));
    Scene scene = new Scene(outerVBox);
    stage.setScene(scene);
    stage.show();
}

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  ww  .  j a  v a2s.  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

@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 -> {/* w ww  .j a va2 s . c o m*/
        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();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Imported Fruits");
    stage.setWidth(500);//from   w w  w .j av a2  s  .c o  m
    stage.setHeight(500);

    ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
            new PieChart.Data("Grapefruit", 13), new PieChart.Data("Oranges", 25),
            new PieChart.Data("Plums", 10), new PieChart.Data("Pears", 22), new PieChart.Data("Apples", 30));

    final PieChart chart = new PieChart(pieChartData);
    chart.setTitle("Imported Fruits");
    final Label caption = new Label("");
    caption.setTextFill(Color.DARKORANGE);
    caption.setStyle("-fx-font: 24 arial;");

    for (final PieChart.Data data : chart.getData()) {
        data.getNode().addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent e) {
                caption.setTranslateX(e.getSceneX());
                caption.setTranslateY(e.getSceneY());
                caption.setText(String.valueOf(data.getPieValue()) + "%");
            }
        });
    }

    ((Group) scene.getRoot()).getChildren().addAll(chart, caption);
    stage.setScene(scene);
    //scene.getStylesheets().add("piechartsample/Chart.css");
    stage.show();
}

From source file:com.bdb.weather.display.current.Thermometer.java

/**
 * Constructor./*from  w  w  w  .ja va  2 s  .c  o  m*/
 * 
 * @param title The title to display in the containing panel
 * @param min The minimum value for the thermometer scale
 * @param max The maximum value for the thermometer scale
 */
public Thermometer(String title, Temperature min, Temperature max) {
    this.setPrefSize(150.0, 200.0);
    minValue = min;
    maxValue = max;
    unitProperty.setValue(Temperature.getDefaultUnit());
    setUnits(unitProperty.getValue());
    ChartViewer chartViewer = createChartElements();
    this.setCenter(chartViewer);
    HBox p = new HBox();
    p.setAlignment(Pos.CENTER);
    Label label = new Label("High: ");
    label.setStyle("-fx-font-weight: bold");
    p.getChildren().addAll(label, highLabel);
    this.setTop(p);
    p = new HBox();
    p.setAlignment(Pos.CENTER);
    label = new Label("Low: ");
    label.setStyle("-fx-font-weight: bold");
    p.getChildren().addAll(label, lowLabel);
    this.setBottom(p);

    unitProperty.addListener((ObservableValue<? extends Temperature.Unit> observable, Temperature.Unit oldValue,
            Temperature.Unit newValue) -> {
        setUnits(newValue);
    });
}

From source file:calendarioSeries.vistas.MainViewController.java

public void showDetallesMes(Mes mes) {
    // System.out.println(mes.getNumAno() + " - " + mes.getNumMes() + "(" + mes.getDiasMes() + ")");
    Platform.runLater(new Runnable() {
        @Override/*from www  . j  a  v a  2 s . c  o  m*/
        public void run() {
            for (Label diasMe : diasMes) {
                diasMe.setStyle("");
                diasMe.setId("");
            }
            labelNombreMes.setText(mes.getNombreMes().toUpperCase());
            labelNumMes.setText(Integer.toString(mes.getNumMes() + 1));
            labelNumAno.setText(Integer.toString(mes.getNumAno()));

            Calendar cal = Calendar.getInstance();
            cal.set(Calendar.MONTH, mes.getNumMes());
            cal.set(Calendar.YEAR, mes.getNumAno());
            cal.set(Calendar.DAY_OF_MONTH, 1);

            int firstDay = cal.getTime().getDay();
            if (firstDay != 0) {
                firstDay -= 1;
            } else {
                firstDay = 6;
            }
            int count = 1;

            for (int i = 0; i < mes.getDiasMes(); i++) {
                String caps = "";
                for (Serie serie : series) {
                    Map<Integer, String> capitulosMes = serie.getCapitulosMes(mes.getNumAno(),
                            mes.getNumMes() + 1);
                    if (capitulosMes.get(count) != null) {
                        for (Map.Entry<Integer, String> entry : capitulosMes.entrySet()) {
                            if (entry.getKey() == count) {
                                if (entry.getValue().length() >= 30) {
                                    caps += serie.getTitulo() + ": +2 caps";
                                } else {
                                    caps += serie.getTitulo() + ": " + entry.getValue();
                                    caps += "\n";
                                }
                            }
                        }
                    }
                }
                diasMes.get(firstDay + i).setText(Integer.toString(count) + "\n\n" + caps);
                if (mes.getNumAno() == esteAno) {
                    if (mes.getNumMes() == esteMes) {
                        if (count == hoy) {
                            diasMes.get(firstDay + i).setId("hoy");
                        } else if (count < hoy) {
                            diasMes.get(firstDay + i).setStyle("-fx-text-fill: grey;");
                        }
                    } else if (mes.getNumMes() < esteMes) {
                        diasMes.get(firstDay + i).setStyle("-fx-text-fill: grey;");
                    }
                } else if (mes.getNumAno() < esteAno) {
                    diasMes.get(firstDay + i).setStyle("-fx-text-fill: grey;");
                }
                count++;
            }
        }
    });
}

From source file:org.sleuthkit.autopsy.timeline.ui.AbstractVisualization.java

/** add a {@link Label} node to the branch container for the decluttered
 * axis labels/*from   ww w  .j a  v  a 2  s .co  m*/
 *
 * @param labelText  the string to add
 * @param labelWidth the width of the space to use for the label
 * @param labelX     the horizontal position in the partPane of the text
 */
private synchronized void assignBranchLabel(String labelText, double labelWidth, double labelX) {

    Label label = new Label(labelText);
    label.setAlignment(Pos.CENTER);
    label.setTextAlignment(TextAlignment.CENTER);
    label.setFont(Font.font(10));
    //use a leading ellipse since that is the lowest frequency part,
    //and can be infered more easily from other surrounding labels
    label.setTextOverrun(OverrunStyle.LEADING_ELLIPSIS);
    //force size
    label.setMinWidth(labelWidth);
    label.setPrefWidth(labelWidth);
    label.setMaxWidth(labelWidth);
    label.relocate(labelX, 0);

    if (labelX == 0) { // first label has no border
        label.setStyle("-fx-border-width: 0 0 0 0 ; -fx-border-color:black;"); // NON-NLS
    } else { // subsequent labels have border on left to create dividers
        label.setStyle("-fx-border-width: 0 0 0 1; -fx-border-color:black;"); // NON-NLS
    }

    branchPane.getChildren().add(label);
}

From source file:org.sleuthkit.autopsy.timeline.ui.AbstractVisualizationPane.java

/**
 * add a {@link Label} node to the branch container for the decluttered axis
 * labels/*from w w w. j  av a  2 s  . c o m*/
 *
 * @param labelText  the string to add
 * @param labelWidth the width of the space to use for the label
 * @param labelX     the horizontal position in the partPane of the text
 */
private synchronized void assignBranchLabel(String labelText, double labelWidth, double labelX) {

    Label label = new Label(labelText);
    label.setAlignment(Pos.CENTER);
    label.setTextAlignment(TextAlignment.CENTER);
    label.setFont(Font.font(10));
    //use a leading ellipse since that is the lowest frequency part,
    //and can be infered more easily from other surrounding labels
    label.setTextOverrun(OverrunStyle.LEADING_ELLIPSIS);
    //force size
    label.setMinWidth(labelWidth);
    label.setPrefWidth(labelWidth);
    label.setMaxWidth(labelWidth);
    label.relocate(labelX, 0);

    if (labelX == 0) { // first label has no border
        label.setStyle("-fx-border-width: 0 0 0 0 ; -fx-border-color:black;"); // NON-NLS //NOI18N
    } else { // subsequent labels have border on left to create dividers
        label.setStyle("-fx-border-width: 0 0 0 1; -fx-border-color:black;"); // NON-NLS //NOI18N
    }

    branchPane.getChildren().add(label);
}

From source file:com.chart.SwingChart.java

/**
 * //www.  java  2s.co  m
 * @param axis Axis name to wich the new series belongs
 * @param cs Series Coinfiguration
 */
@Override
public final void addSeries(String axis, SimpleSeriesConfiguration cs) {
    for (int i = 0; i < axes.size(); i++) {
        if (axes.get(i).getName().equals(axis)) {
            String strColor;
            javafx.scene.paint.Color color;
            int indice = seriesList.size();
            if (cs.getColor() == null) {
                color = getColor(indice);
            } else {
                color = cs.getColor();
            }
            strColor = color.toString();

            XYSeriesCollection dataset = datasetList.get(i);
            Series series = new Series(cs.getName(), "color: " + strColor + ";width: "
                    + String.valueOf(cs.getLineWidth()) + ";shape: " + cs.getShapeName() + ";", i,
                    dataset.getSeriesCount());
            dataset.addSeries(series);

            XYItemRenderer renderer = plot.getRenderer(i);
            renderer.setSeriesPaint(dataset.getSeriesCount() - 1, scene2awtColor(color));

            SeriesShape simb = new SeriesShape(cs.getShapeName(),
                    javafx.scene.paint.Color.web(strColor.replace("#", "0x")));

            if (cs.getLineWidth() > 0) {
                ((XYLineAndShapeRenderer) renderer).setSeriesLinesVisible(dataset.getSeriesCount() - 1, true);
                renderer.setSeriesStroke(dataset.getSeriesCount() - 1, new BasicStroke(cs.getLineWidth()));
            } else {
                ((XYLineAndShapeRenderer) renderer).setSeriesLinesVisible(dataset.getSeriesCount() - 1, false);
            }

            if (cs.getShapeName().equals("null")) {
                renderer.setSeriesShape(dataset.getSeriesCount() - 1, null);
                ((XYLineAndShapeRenderer) renderer).setSeriesShapesVisible(dataset.getSeriesCount() - 1, false);
            } else {
                renderer.setSeriesShape(dataset.getSeriesCount() - 1, simb.getShapeAWT());
                ((XYLineAndShapeRenderer) renderer).setSeriesShapesVisible(dataset.getSeriesCount() - 1, true);
                if (cs.getShapeName().contains("empty")) {
                    ((XYLineAndShapeRenderer) renderer).setSeriesShapesFilled(dataset.getSeriesCount() - 1,
                            false);
                } else {
                    ((XYLineAndShapeRenderer) renderer).setSeriesShapesFilled(dataset.getSeriesCount() - 1,
                            true);
                }
            }

            if (i == 0) {
                plot.setRenderer(renderer);
            } else {
                plot.setRenderer(i, renderer);
            }

            seriesList.add(series);

            final LegendAxis le = getLegendAxis(axis);
            final Label label = new Label(cs.toString());
            Platform.runLater(() -> {
                label.setStyle("fondo: " + strChartBackgroundColor
                        + ";-fx-background-color: fondo;-fx-text-fill: ladder(fondo, white 49%, black 50%);-fx-padding:5px;-fx-background-radius: 5;-fx-font-size: "
                        + String.valueOf(fontSize) + "px");
            });

            label.setOnMouseClicked((MouseEvent t) -> {
                if (t.getClickCount() == 2) {
                    for (int i1 = 0; i1 < seriesList.size(); i1++) {
                        if (seriesList.get(i1).getKey().toString().equals(label.getText())) {
                            editSeries(seriesList.get(i1));
                            break;
                        }
                    }
                }
            });
            label.setOnMouseExited((MouseEvent t) -> {
                label.setStyle(
                        label.getStyle().replace("-fx-background-color: blue", "-fx-background-color: fondo"));
            });
            label.setOnMouseEntered((MouseEvent t) -> {
                label.setStyle(
                        label.getStyle().replace("-fx-background-color: fondo", "-fx-background-color: blue"));
                for (Node le1 : legendFrame.getChildren()) {
                    if (le1 instanceof LegendAxis) {
                        le1.setStyle("-fx-background-color:" + strBackgroundColor);
                        ((LegendAxis) le1).selected = false;
                    }
                }
            });
            label.setStyle("fondo: " + strChartBackgroundColor
                    + ";-fx-text-fill: white;-fx-background-color: fondo;-fx-padding:5px;-fx-background-radius: 5;-fx-font-size: "
                    + String.valueOf(fontSize) + "px");

            le.getChildren().add(label);
            label.setGraphic(simb.getShapeGraphic());

            break;
        }
    }
}

From source file:view.FXApplicationController.java

public void showLabelsForEpoch() {

    overlay.getChildren().clear();//ww  w . j  ava 2 s  .com

    double offsetSize = 1. / (activeChannels.size() + 1);

    for (int i = 0; i < activeChannels.size(); i++) {

        double realOffset = (i + 1.) * offsetSize;

        Label label = new Label(channelNames[activeChannels.get(i)]);
        label.setTextFill(Color.GRAY);
        label.setStyle("-fx-font-family: sans-serif;");
        label.setLayoutX(1);

        label.layoutYProperty().bind(yAxis.heightProperty().multiply(realOffset).add(yAxis.layoutYProperty()));

        overlay.getChildren().add(label);

    }

}