小编use*_*546的帖子

如何将CSS样式表附加到FXML?

在Oracle教程http://docs.oracle.com/javafx/2/get_started/fxml_tutorial.htm之后,我用片段创建FXML

<?xml version="1.0" encoding="UTF-8"?>

<?language javascript?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<GridPane alignment="CENTER" gridLinesVisible="true" hgap="10.0" vgap="10.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="fxmlexample.FXMLExampleController" styleClass="root" >
...other stuff...
<stylesheets>
    <URL value="@Login.css" />
</stylesheets>
</GridPane>
Run Code Online (Sandbox Code Playgroud)

NetBeans 8.0将URL着色为红色,并说:"类不存在:URL".

编译和运行时,JRE 1.8也会抛出异常:

...
Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:894)
    at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:56)
    at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:158)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException: URL is not a valid type.
file:/C:/Users/User1/Documents/NetBeansProjects/FXMLExample/dist/run1970052180/FXMLExample.jar!/fxmlexample/fxml_example.fxml:46
Run Code Online (Sandbox Code Playgroud)

如果我在JavaFX Scene Builder 1.1中 …

css javafx fxml

6
推荐指数
1
解决办法
6977
查看次数

标签 统计

css ×1

fxml ×1

javafx ×1