JavaFX给控件添加css样式

た 入场券 2023-10-04 14:32 22阅读 0赞

编写样式

  1. .label{
  2. -fx-text-fill: #00a707;
  3. }

选择样式

在这里插入图片描述

应用样式

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <?import javafx.scene.control.*?>
  3. <?import javafx.scene.layout.*?>
  4. <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">
  5. <children>
  6. <Button layoutX="273.0" layoutY="189.0" mnemonicParsing="false" onAction="#test" text="我是按钮" />
  7. <Label fx:id="label2" layoutX="273.0" layoutY="151.0" text="Label" />
  8. </children>
  9. </AnchorPane>

效果展示

在这里插入图片描述
在这里插入图片描述

补充说明

<build>中无需配置resources标签!!!

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>cn.zxl</groupId>
  5. <artifactId>fxdemo</artifactId>
  6. <version>1.0-SNAPSHOT</version>
  7. <packaging>jar</packaging>
  8. <name>JavaFXDemo</name>
  9. <url>http://maven.apache.org</url>
  10. <properties>
  11. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  12. <maven.compiler.source>1.8</maven.compiler.source>
  13. <maven.compiler.target>1.8</maven.compiler.target>
  14. <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
  15. </properties>
  16. <build>
  17. <finalName>HelloJavaFX</finalName>
  18. <plugins>
  19. <plugin>
  20. <groupId>org.apache.maven.plugins</groupId>
  21. <artifactId>maven-compiler-plugin</artifactId>
  22. <version>3.6.1</version>
  23. <configuration>
  24. <source>${
  25. maven.compiler.source}</source>
  26. <target>${
  27. maven.compiler.target}</target>
  28. </configuration>
  29. </plugin>
  30. <plugin>
  31. <groupId>org.apache.maven.plugins</groupId>
  32. <artifactId>maven-jar-plugin</artifactId>
  33. <version>3.0.2</version>
  34. <configuration>
  35. <outputDirectory>${
  36. project.build.directory}</outputDirectory>
  37. <archive>
  38. <manifest>
  39. <addClasspath>true</addClasspath>
  40. <classpathPrefix>libs/</classpathPrefix>
  41. <mainClass>cn.zxl.MainApp</mainClass>
  42. </manifest>
  43. </archive>
  44. </configuration>
  45. </plugin>
  46. </plugins>
  47. </build>
  48. <dependencies>
  49. <dependency>
  50. <groupId>com.jfoenix</groupId>
  51. <artifactId>jfoenix</artifactId>
  52. <version>8.0.10</version>
  53. </dependency>
  54. </dependencies>
  55. </project>

发表评论

表情:
评论列表 (有 0 条评论,22人围观)

还没有评论,来说两句吧...

相关阅读