JavaFX给控件添加css样式
生活随笔
收集整理的這篇文章主要介紹了
JavaFX给控件添加css样式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
編寫樣式
.label{-fx-text-fill: #00a707; }選擇樣式
應用樣式
<?xml version="1.0" encoding="UTF-8"?><?import javafx.scene.control.*?> <?import javafx.scene.layout.*?><AnchorPane prefHeight="400.0" prefWidth="600.0" stylesheets="/css/main.css" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="cn.zxl.Controller.Controller"><children><Button layoutX="273.0" layoutY="189.0" mnemonicParsing="false" onAction="#test" text="我是按鈕" /><Label fx:id="label2" layoutX="273.0" layoutY="151.0" text="Label" /></children> </AnchorPane>效果展示
補充說明
<build>中無需配置resources標簽!!!
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>cn.zxl</groupId><artifactId>fxdemo</artifactId><version>1.0-SNAPSHOT</version><packaging>jar</packaging><name>JavaFXDemo</name><url>http://maven.apache.org</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion></properties><build><finalName>HelloJavaFX</finalName><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.6.1</version><configuration><source>${maven.compiler.source}</source><target>${maven.compiler.target}</target></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><version>3.0.2</version><configuration><outputDirectory>${project.build.directory}</outputDirectory><archive><manifest><addClasspath>true</addClasspath><classpathPrefix>libs/</classpathPrefix><mainClass>cn.zxl.MainApp</mainClass></manifest></archive></configuration></plugin></plugins></build><dependencies><dependency><groupId>com.jfoenix</groupId><artifactId>jfoenix</artifactId><version>8.0.10</version></dependency></dependencies> </project>總結
以上是生活随笔為你收集整理的JavaFX给控件添加css样式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JavaFX控件ID:设置Label文本
- 下一篇: JavaFX maven工程pom文件完