create JavaFX Label - Java JavaFX

Java examples for JavaFX:Label

Description

create JavaFX Label

Demo Code


//package com.java2s;

import javafx.geometry.Pos;

import javafx.scene.control.Label;

import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;

public class Main {
    private static Font defaultLabelFont = Font.font("Tahoma",
            FontWeight.LIGHT, 14);//ww  w  . j  av a 2  s.com

    public static Label createLabel(GridPane gridPane, String labelStr,
            int colIndex, int rowIndex) {
        return createLabel(gridPane, labelStr, 0, colIndex, rowIndex);
    }

    public static Label createLabel(GridPane gridPane, String labelStr,
            int maxWidth, int colIndex, int rowIndex) {
        Label label = new Label(labelStr);
        label.setFont(defaultLabelFont);
        label.setAlignment(Pos.CENTER);
        if (maxWidth != 0) {
            label.setPrefWidth(maxWidth);
        }
        gridPane.add(label, colIndex, rowIndex);

        return label;
    }
}

Related Tutorials