2013-04-29 72 views
3

我正在使用JavaFX開發多平臺應用程序,並且我使用Win7和NetBeans 7.2.1以及JavaFX 2.2和Java 1.7u21(以前使用的是1.7u9,並且工作也很棒)。正如我所說,Win7運行得很好,我的應用程序。 當我嘗試在Ubuntu 12.04上運行它時,它無法加載我的CSS樣式。每個fxml文件都添加了其控件的樣式表類。然後每個控件都添加了它的樣式。 例如:在一個空白的按鈕,我在申請這種風格:JavaFX - CSS無法在Linux中加載

buttonStyle.css:

.button { 
    -fx-text-fill: white; 
    -fx-alignment: CENTER; 
    -fx-border-radius: 5; 
    -fx-font-size: 13pt; 
    -fx-font-family: "Verdana"; 
    -fx-font-weight: bold; 
    -fx-background-color: linear-gradient(#328BDB 0%, #207BCF 25%, #1973C9 75%, #0A65BF 100%); 
} 

.button:hover { 
    -fx-background-color: linear-gradient(#2C8AE7 0%, #0C6AC7 25%, #0A58A5 75%, #093B6D 100%); 
} 

.button:pressed { 
    -fx-background-color: linear-gradient(#328BDB 0%, #207BCF 25%, #1973C9 75%, #0A65BF 100%); 
} 

Win7上工作正常,但它產生在Ubuntu以下異常:

java.lang.ClassNotFoundException: AUTHOR Exception in Application start method java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at com.javafx.main.Main.launchApp(Main.java:642) at com.javafx.main.Main.main(Main.java:805) Caused by: java.lang.RuntimeException: Exception in Application start method at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403) at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47) at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115) at java.lang.Thread.run(Thread.java:722) Caused by: java.lang.ArrayIndexOutOfBoundsException: 512 at com.sun.javafx.css.StyleConverter.readBinary(StyleConverter.java:99) at com.sun.javafx.css.ParsedValue.readBinary(ParsedValue.java:600) at com.sun.javafx.css.Declaration.readBinary(Declaration.java:142) at com.sun.javafx.css.Rule.readBinary(Rule.java:189) at com.sun.javafx.css.Stylesheet.readBinary(Stylesheet.java:185) at com.sun.javafx.css.Stylesheet.loadBinary(Stylesheet.java:215) at com.sun.javafx.css.StyleManager.loadStylesheetUnPrivileged(StyleManager.java:572) at com.sun.javafx.css.StyleManager.loadStylesheet(StyleManager.java:411) at com.sun.javafx.css.StyleManager.access$1900(StyleManager.java:72) at com.sun.javafx.css.StyleManager$StylesheetContainer.gatherParentStylesheets(StyleManager.java:1140) at com.sun.javafx.css.StyleManager$StylesheetContainer.getStyleHelper(StyleManager.java:1225) at com.sun.javafx.css.StyleManager$StylesheetContainer.access$1300(StyleManager.java:1031) at com.sun.javafx.css.StyleManager.getStyleHelper(StyleManager.java:968) at javafx.scene.Node.impl_createStyleHelper(Node.java:7433) at javafx.scene.Node.impl_processCSS(Node.java:7403) at javafx.scene.Parent.impl_processCSS(Parent.java:1146) at javafx.scene.Parent.impl_processCSS(Parent.java:1153) at javafx.scene.Parent.impl_processCSS(Parent.java:1153) at javafx.scene.Node.processCSS(Node.java:7383) at javafx.scene.Scene.doCSSPass(Scene.java:443) at javafx.scene.Scene.preferredSize(Scene.java:1445) at javafx.scene.Scene.impl_preferredSize(Scene.java:1512) at javafx.stage.Window$10.invalidated(Window.java:719) at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:127) at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:161) at javafx.stage.Window.setShowing(Window.java:782) at javafx.stage.Window.show(Window.java:797) at javafx.stage.Stage.show(Stage.java:229) at com.test.MainInterface.start(MainInterface.java:62) at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319) at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:206) at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76) at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method) at com.sun.glass.ui.gtk.GtkApplication$3$1.run(GtkApplication.java:82) ... 1 more

刪除buttonStyle.css和添加comboStyle.css,以下異常被拋出:

comboStyle。 CSS:

.combo-box { 
    -fx-font: 13pt "Verdana"; 
    -fx-alignment: baseline-left; 
    -fx-background-color: linear-gradient(#328BDB 0%, #207BCF 25%, #1973C9 75%, #0A65BF 100%); 
} 

.combo-box .text { 
    -fx-fill: white; 
} 

.combo-box .arrow-button { 
    -fx-background-color: linear-gradient(#328BDB 0%, #207BCF 25%, #1973C9 75%, #0A65BF 100%); 
} 

.combo-box .arrow { 
    -fx-background-color: white; 
} 

例外: java.io.EOFException at java.io.DataInputStream.readByte(DataInputStream.java:267) at com.sun.javafx.css.CompoundSelector.readBinary(CompoundSelector.java:351) at com.sun.javafx.css.Selector.readBinary(Selector.java:113) at com.sun.javafx.css.CompoundSelector.readBinary(CompoundSelector.java:344) at com.sun.javafx.css.Selector.readBinary(Selector.java:113) at com.sun.javafx.css.Rule.readBinary(Rule.java:182) at com.sun.javafx.css.Stylesheet.readBinary(Stylesheet.java:185) at com.sun.javafx.css.Stylesheet.loadBinary(Stylesheet.java:215) at com.sun.javafx.css.StyleManager.loadStylesheetUnPrivileged(StyleManager.java:572) at com.sun.javafx.css.StyleManager.loadStylesheet(StyleManager.java:411) at com.sun.javafx.css.StyleManager.access$1900(StyleManager.java:72) at com.sun.javafx.css.StyleManager$StylesheetContainer.gatherParentStylesheets(StyleManager.java:1140) at com.sun.javafx.css.StyleManager$StylesheetContainer.getStyleHelper(StyleManager.java:1225) at com.sun.javafx.css.StyleManager$StylesheetContainer.access$1300(StyleManager.java:1031) at com.sun.javafx.css.StyleManager.getStyleHelper(StyleManager.java:968) at javafx.scene.Node.impl_createStyleHelper(Node.java:7433) at javafx.scene.Node.impl_processCSS(Node.java:7403) at javafx.scene.Parent.impl_processCSS(Parent.java:1146) at javafx.scene.Parent.impl_processCSS(Parent.java:1153) at javafx.scene.Parent.impl_processCSS(Parent.java:1153) at javafx.scene.Node.processCSS(Node.java:7383) at javafx.scene.Scene.doCSSPass(Scene.java:443) at javafx.scene.Scene.preferredSize(Scene.java:1445) at javafx.scene.Scene.impl_preferredSize(Scene.java:1512) at javafx.stage.Window$10.invalidated(Window.java:719) at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:127) at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:161) at javafx.stage.Window.setShowing(Window.java:782) at javafx.stage.Window.show(Window.java:797) at javafx.stage.Stage.show(Stage.java:229) at com.test.MainInterface.start(MainInterface.java:62) at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319) at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:206) at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76) at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method) at com.sun.glass.ui.gtk.GtkApplication$3$1.run(GtkApplication.java:82) at java.lang.Thread.run(Thread.java:722)

任何想法,爲什麼這些樣式不能在Linux的加載?

+1

任何想法如何解決呢? – Leonardo 2013-05-06 19:08:26

回答

1

我剛找到解決方法。我在我的FXML文件上設置了所有的CSS引用。另外,我正在閱讀有關將CSS文件自動轉換爲二進制文件(.bss)的文章。 後來我一直在研究一個辦法取消這個皈依我的Maven項目,像波紋管:

<plugin> 
    <groupId>com.zenjava</groupId> 
    <artifactId>javafx-maven-plugin</artifactId> 
    <version>1.5</version> 
    <configuration> 
     <mainClass>package.mainClass</mainClass> 
     <css2bin>false</css2bin> <!-- THIS LINE --> 

     ... 
    </configuration> 
</plugin> 

其他類型的項目可以使用-Dbinary.css = false作爲運行參數,以避免這種皈依。

最後,我只是把我所有的CSS加載使用我的控制器類:

anchorPaneScene1.getStylesheets().add("/path/to/resources/css/button.css") 
button1.getStyleClass().add("button");