javaFX简单实践(五)——标签

显示包括六个标签的界面。 

将标签背景色设置为白色。将标签前景色分别

设置为黑色、蓝色、青色、绿色、洋红色和橙色,如图1所示。 

设置每个标签的边界为黄色的线边界。 

设置每个标签的字体为Times Roman、加粗、20像素。 

将每个标签的文本和工具

 

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.control.Label;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;


public class SixLable extends Application {
    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle("Six Lable");
        FlowPane fp = new FlowPane();//保持水平布局,自动换行
        Scene scene = new Scene(fp, 600, 200);
    //创建
        Label labelBlack = new Label("Black");
        Label labelBlue = new Label("Blue");
        Label labelCyan = new Label("Cyan");
        Label labelGreen = new Label("Green");
        Label labelMagenta = new Label("Magenta");
        Label labelOrange = new Label("Orange");
    //字体、大小、加粗
        labelBlack.setFont(Font.font("Times Roman", FontWeight.BOLD, 20));
        labelBlue.setFont(Font.font("Times Roman", FontWeight.BOLD, 20));
        labelCyan.setFont(Font.font("Times Roman", FontWeight.BOLD, 20));
        labelGreen.setFont(Font.font("Times Roman", FontWeight.BOLD, 20));
        labelMagenta.setFont(Font.font("Times Roman", FontWeight.BOLD, 20));
        labelOrange.setFont(Font.font("Times Roman", FontWeight.BOLD, 20));
    //设置背景色
        labelBlack.setBackground(new Background(new BackgroundFill(Color.WHITE, null, null)));
        labelBlue.setBackground(new Background(new BackgroundFill(Color.WHITE, null, null)));
        labelCyan.setBackground(new Background(new BackgroundFill(Color.WHITE, null, null)));
        labelGreen.setBackground(new Background(new BackgroundFill(Color.WHITE, null, null)));
        labelMagenta.setBackground(new Background(new BackgroundFill(Color.WHITE, null, null)));
        labelOrange.setBackground(new Background(new BackgroundFill(Color.WHITE, null, null)));
    //设置前景色
        labelBlack.setTextFill(Color.BLACK);
        labelBlue.setTextFill(Color.BLUE);
        labelCyan.setTextFill(Color.CYAN);
        labelGreen.setTextFill(Color.GREEN);
        labelMagenta.setTextFill(Color.MAGENTA);
        labelOrange.setTextFill(Color.ORANGE);
    //边框
        //三个参数:颜色、边框笔画样式、拐角圆弧半径、边框宽度
        labelBlack.setBorder(new Border(new BorderStroke(Color.YELLOW, BorderStrokeStyle.SOLID, new CornerRadii(10), new BorderWidths(3))));
        labelBlue.setBorder(new Border(new BorderStroke(Color.YELLOW, BorderStrokeStyle.SOLID, new CornerRadii(10), new BorderWidths(3))));
        labelCyan.setBorder(new Border(new BorderStroke(Color.YELLOW, BorderStrokeStyle.SOLID, new CornerRadii(10), new BorderWidths(3))));
        labelGreen.setBorder(new Border(new BorderStroke(Color.YELLOW, BorderStrokeStyle.SOLID, new CornerRadii(10), new BorderWidths(3))));
        labelMagenta.setBorder(new Border(new BorderStroke(Color.YELLOW, BorderStrokeStyle.SOLID, new CornerRadii(10), new BorderWidths(3))));
        labelOrange.setBorder(new Border(new BorderStroke(Color.YELLOW, BorderStrokeStyle.SOLID, new CornerRadii(10), new BorderWidths(3))));
    //工具提示
        Tooltip.install(labelBlack,new Tooltip("Black"));
        Tooltip.install(labelBlue,new Tooltip("Blue"));
        Tooltip.install(labelCyan,new Tooltip("Cyan"));
        Tooltip.install(labelGreen,new Tooltip("Green"));
        Tooltip.install(labelMagenta,new Tooltip("Magenta"));
        Tooltip.install(labelOrange,new Tooltip("Orange"));

        fp.getChildren().addAll(labelBlack,labelBlue,labelCyan,labelGreen,labelMagenta,labelOrange);

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

提示文本都设置为它的前景色的名字。

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值