当前位置: 首页 > 工具软件 > cssFx > 使用案例 >

java fx 加载css,Java CSSFX类代码示例

孔权
2023-12-01

import org.fxmisc.cssfx.CSSFX; //导入依赖的package包/类

@Override

public void start(Stage primaryStage) {

HostServiceSingleton.setInstance(getHostServices()); //weigl: ???

this.mainScene = new StvsMainScene();

this.primaryStage = new Stage();

Platform.setImplicitExit(true);

primaryStage.setTitle(StvsVersion.getWindowTitle());

primaryStage.setScene(mainScene.getScene());

primaryStage.setMaximized(mainScene.shouldBeMaximizedProperty().get());

primaryStage.getIcons().addAll(

new Image(StvsApplication.class.getResourceAsStream("logo_large.png")),

new Image(StvsApplication.class.getResourceAsStream("logo.png")));

mainScene.shouldBeMaximizedProperty().bind(primaryStage.maximizedProperty());

mainScene.getScene().getStylesheets().add(

StvsApplication.class.getResource("normal.css").toExternalForm()

);

CSSFX.start(mainScene.getScene());

//Debugger snippet for finding the styleclasses for the node under cursor.

mainScene.getScene().addEventFilter(MouseEvent.MOUSE_MOVED, mouseEvent -> {

if (mouseEvent.isAltDown() && mouseEvent.isControlDown()) {

try {

Node node = (Node) mouseEvent.getTarget();

ObservableList classes = node.getStyleClass();

System.out.println("Classes of " + node.getClass().getSimpleName() + " are " + classes);

System.out.println("Style of " + node.getClass().getSimpleName() + ": " + node.getStyle());

System.out.println(((TitledPane) node).getAlignment());

System.out.println(((TitledPane) node).getTextAlignment());

} catch (ClassCastException e) {

}

}

});

if (System.getProperty("presentation", "false").equals("true")) {

mainScene.getScene().getStylesheets().add(

StvsApplication.class.getResource("presentation.css").toExternalForm()

);

}

if (mainScene.getRootController().getRootModel().isFirstStart()) {

new WelcomeWizard(mainScene.getRootController().getRootModel().getGlobalConfig())

.showAndWait();

}

primaryStage.show();

}

 类似资料: