java stylesheet_StyleSheetDemo.java

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.layout.HBox;

import javafx.scene.layout.Pane;

import javafx.scene.shape.Circle;

import javafx.stage.Stage;

public class StyleSheetDemo extends Application {

@Override // Override the start method in the Application class

public void start(Stage primaryStage) {

HBox hBox = new HBox(5);

Scene scene = new Scene(hBox, 300, 250);

scene.getStylesheets().add("mystyle.css"); // Load the stylesheet

Pane pane1 = new Pane();

Circle circle1 = new Circle(50, 50, 30);

Circle circle2 = new Circle(150, 50, 30);

Circle circle3 = new Circle(100, 100, 30);

pane1.getChildren().addAll(circle1, circle2, circle3);

pane1.getStyleClass().add("border");

circle1.getStyleClass().add("plaincircle"); // Add a style class

circle2.getStyleClass().add("plaincircle"); // Add a style class

circle3.setId("redcircle"); // Add a style id

Pane pane2 = new Pane();

Circle circle4 = new Circle(100, 100, 30);

circle4.getStyleClass().addAll("circleborder", "plainCircle");

circle4.setId("greencircle"); // Add a style class

pane2.getChildren().add(circle4);

pane2.getStyleClass().add("border");

hBox.getChildren().addAll(pane1, pane2);

primaryStage.setTitle("StyleSheetDemo"); // Set the window title

primaryStage.setScene(scene); // Place the scene in the window

primaryStage.show(); // Display the window

}

// Lauch the program from command-line

public static void main(String[] args) {

launch(args);

}

}

一键复制

编辑

Web IDE

原始数据

按行查看

历史

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值