简体   繁体   English

CSS解析文件JavaFX时出错,但是我不知道它错了什么

[英]CSS Error parsing file JavaFX but i have no clue what it wrong

From my program i receive this error: Eclipse console output 从我的程序中,我收到以下错误: Eclipse控制台输出

All i am trying to do is use the hover effect on buttons to turn the text white. 我要做的就是在按钮上使用悬停效果以将文本变为白色。 Here is my code: Main.java: 这是我的代码:Main.java:

import java.util.Date;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.TableView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Main extends Application {


public static void main(String[] args) {
    launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception {
    Pane mainPane = (Pane) FXMLLoader.load(Main.class.getResource("Main.fxml"));
    primaryStage.setScene(new Scene(mainPane));
    primaryStage.show();
    }

}

Here is my Main.fxml file: 这是我的Main.fxml文件:

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

<?import javafx.scene.image.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>

<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="318.0" prefWidth="1000.0" stylesheets="@myStyle.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="MyController">
   <children>
      <TextField fx:id="tf_input" alignment="BOTTOM_RIGHT" editable="true" layoutX="450.0" layoutY="22.0" prefHeight="35.0" prefWidth="300.0" styleClass="display">
         <font>
            <Font name="Lucida Console" size="20.0" />
         </font>
         <effect>
            <DropShadow />
         </effect>
      </TextField>
      <Button fx:id="bOne" layoutX="472.0" layoutY="102.0" mnemonicParsing="false" onAction="#click1" prefHeight="35.0" prefWidth="64.0" text="1" />
      <Button fx:id="bTwo" layoutX="536.0" layoutY="102.0" mnemonicParsing="false" onAction="#click2" prefHeight="35.0" prefWidth="64.0" text="2" />
      <Button fx:id="bThree" layoutX="600.0" layoutY="102.0" mnemonicParsing="false" onAction="#click3" prefHeight="35.0" prefWidth="64.0" text="3" />
      <Button fx:id="bSix" layoutX="600.0" layoutY="137.0" mnemonicParsing="false" onAction="#click6" prefHeight="35.0" prefWidth="64.0" text="6" />
      <Button fx:id="bFive" layoutX="536.0" layoutY="137.0" mnemonicParsing="false" onAction="#click5" prefHeight="35.0" prefWidth="64.0" text="5" />
      <Button fx:id="bFour" layoutX="472.0" layoutY="137.0" mnemonicParsing="false" onAction="#click4" prefHeight="35.0" prefWidth="64.0" text="4" />
      <Button fx:id="bNine" layoutX="600.0" layoutY="172.0" mnemonicParsing="false" onAction="#click9" prefHeight="35.0" prefWidth="64.0" text="9" />
      <Button fx:id="bEight" layoutX="536.0" layoutY="172.0" mnemonicParsing="false" onAction="#click8" prefHeight="35.0" prefWidth="64.0" text="8" />
      <Button fx:id="bSeven" layoutX="472.0" layoutY="172.0" mnemonicParsing="false" onAction="#click7" prefHeight="35.0" prefWidth="64.0" text="7" />
      <Button fx:id="bB" layoutX="536.0" layoutY="207.0" mnemonicParsing="false" onAction="#clickB" prefHeight="35.0" prefWidth="64.0" text="B" />
      <Button fx:id="bA" layoutX="472.0" layoutY="207.0" mnemonicParsing="false" onAction="#clickA" prefHeight="35.0" prefWidth="64.0" text="A" />
      <Button fx:id="bZero" layoutX="472.0" layoutY="68.0" mnemonicParsing="false" onAction="#click0" prefHeight="35.0" prefWidth="64.0" text="0" />
      <Button fx:id="bE" layoutX="536.0" layoutY="242.0" mnemonicParsing="false" onAction="#clickE" prefHeight="35.0" prefWidth="64.0" text="E" />
      <Button fx:id="bD" layoutX="472.0" layoutY="242.0" mnemonicParsing="false" onAction="#clickD" prefHeight="35.0" prefWidth="64.0" text="D" />
      <Button fx:id="bC" layoutX="600.0" layoutY="207.0" mnemonicParsing="false" onAction="#clickC" prefHeight="35.0" prefWidth="64.0" text="C" />
      <Button fx:id="bF" layoutX="600.0" layoutY="242.0" mnemonicParsing="false" onAction="#clickF" prefHeight="35.0" prefWidth="64.0" text="F" />
      <Button fx:id="bPlus" layoutX="664.0" layoutY="102.0" mnemonicParsing="false" onAction="#clickplus" prefHeight="35.0" prefWidth="64.0" text="+" />
      <Button fx:id="bMinus" layoutX="664.0" layoutY="137.0" mnemonicParsing="false" onAction="#clickminus" prefHeight="35.0" prefWidth="64.0" text="-" />
      <Button fx:id="bDivide" layoutX="664.0" layoutY="207.0" mnemonicParsing="false" onAction="#clickdivide" prefHeight="35.0" prefWidth="64.0" text="/" />
      <Button fx:id="bTimes" layoutX="664.0" layoutY="172.0" mnemonicParsing="false" onAction="#clicktimes" prefHeight="35.0" prefWidth="64.0" text="*" />
      <Button fx:id="bEquals" layoutX="664.0" layoutY="242.0" mnemonicParsing="false" onAction="#clickequals" prefHeight="35.0" prefWidth="64.0" text="=" />
      <Label alignment="CENTER" layoutX="798.0" layoutY="21.0" prefHeight="23.0" prefWidth="161.0" styleClass="display" text="Output:">
         <font>
            <Font name="Lucida Console" size="20.0" />
         </font>
      </Label>
          <TextField fx:id="tf_output" alignment="BOTTOM_RIGHT" editable="false" layoutX="769.0" layoutY="68.0" prefHeight="153.0" prefWidth="219.0" styleClass="display">
         <font>
            <Font name="Lucida Console" size="20.0" />
         </font>
         <effect>
            <InnerShadow />
         </effect>
      </TextField>
      <Button fx:id="bAc" layoutX="600.0" layoutY="68.0" mnemonicParsing="false" onAction="#clickclear" prefHeight="35.0" prefWidth="64.0" text="AC" />
      <Button fx:id="bDel" layoutX="536.0" layoutY="68.0" mnemonicParsing="false" onAction="#clickdel" prefHeight="35.0" prefWidth="64.0" text="DEL" />
      <Button fx:id="bSquare" layoutX="664.0" layoutY="68.0" mnemonicParsing="false" onAction="#clicksquare" prefHeight="35.0" prefWidth="64.0" text="^2" />
      <RadioButton fx:id="Insixteen" layoutX="50.0" layoutY="121.0" mnemonicParsing="false" onAction="#clickin16" selected="true" text="Base 16 (Hex)" />
      <RadioButton fx:id="Inten" layoutX="50.0" layoutY="87.0" mnemonicParsing="false" onAction="#clickin10" text="Base 10 (Denary)" />
      <RadioButton fx:id="Intwo" layoutX="50.0" layoutY="53.0" mnemonicParsing="false" onAction="#clickin2" text="Base 2 (Binary)" />
      <Label alignment="BOTTOM_RIGHT" layoutX="50.0" layoutY="22.0" prefHeight="21.0" prefWidth="136.0" text="Base Input:" underline="true">
         <font>
            <Font name="Lucida Console" size="20.0" />
         </font>
      </Label>
      <Label alignment="BOTTOM_RIGHT" layoutX="234.0" layoutY="22.0" prefHeight="21.0" prefWidth="147.0" text="Base Output:" underline="true">
         <font>
            <Font name="Lucida Console" size="20.0" />
         </font>
      </Label>
      <RadioButton fx:id="Outtwo" layoutX="234.0" layoutY="53.0" mnemonicParsing="false" onAction="#clickout2" text="Base 2 (Binary)" />
      <RadioButton fx:id="Outten" layoutX="234.0" layoutY="87.0" mnemonicParsing="false" onAction="#clickout10" selected="true" text="Base 10 (Denary)" />
      <RadioButton fx:id="Outsixteen" layoutX="234.0" layoutY="121.0" mnemonicParsing="false" onAction="#clickout16" text="Base 16 (Hex)" />
   </children>
</Pane>

Here is MyController.java: 这是MyController.java:

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;

public class MyController {

@FXML
private RadioButton Inten;

@FXML
private Button bMinus;

@FXML
private Button bTimes;

@FXML
private Button bOne;

@FXML
private Button bSix;

@FXML
private Button bDivide;

@FXML
private Button bEquals;

@FXML
private TextField tf_output;

@FXML
private Button bThree;

@FXML
private Button bPlus;

@FXML
private RadioButton Outten;

@FXML
private Button bA;

@FXML
private RadioButton Intwo;

@FXML
private Button bB;

@FXML
private Button bC;

@FXML
private Button bD;

@FXML
private Button bE;

@FXML
private Button bF;

@FXML
private Button bDel;

@FXML
private Button bZero;

@FXML
private Button bAc;

@FXML
private TextField tf_input;

@FXML
private Button bTwo;

@FXML
private RadioButton Outtwo;

@FXML
private Button bSquare;

@FXML
private RadioButton Outsixteen;

@FXML
private Button bFour;

@FXML
private Button bFive;

@FXML
private Button bEight;

@FXML
private Button bSeven;

@FXML
private RadioButton Insixteen;

@FXML
private Button bNine;

@FXML
void click1(ActionEvent event) {

}

@FXML
void click2(ActionEvent event) {

}

@FXML
void click3(ActionEvent event) {

}

@FXML
void click6(ActionEvent event) {

}

@FXML
void click5(ActionEvent event) {

}

@FXML
void click4(ActionEvent event) {

}

@FXML
void click9(ActionEvent event) {

}

@FXML
void click8(ActionEvent event) {

}

@FXML
void click7(ActionEvent event) {

}

@FXML
void clickB(ActionEvent event) {

}

@FXML
void clickA(ActionEvent event) {

}

@FXML
void click0(ActionEvent event) {

}

@FXML
void clickE(ActionEvent event) {

}

@FXML
void clickD(ActionEvent event) {

}

@FXML
void clickC(ActionEvent event) {

}

@FXML
void clickF(ActionEvent event) {

}

@FXML
void clickplus(ActionEvent event) {

}

@FXML
void clickminus(ActionEvent event) {

}

@FXML
void clickdivide(ActionEvent event) {

}

@FXML
void clicktimes(ActionEvent event) {

}

@FXML
void clickequals(ActionEvent event) {

}

@FXML
void clickclear(ActionEvent event) {

}

@FXML
void clickdel(ActionEvent event) {

}

@FXML
void clicksquare(ActionEvent event) {

}

@FXML
void clickin16(ActionEvent event) {

}

@FXML
void clickin10(ActionEvent event) {

}

@FXML
void clickin2(ActionEvent event) {

}

@FXML
void clickout2(ActionEvent event) {

}

@FXML
void clickout10(ActionEvent event) {

}

@FXML
void clickout16(ActionEvent event) {

}

}

Finally here is my myStyle.css file: 最后是我的myStyle.css文件:

@charset "ISO-8859-1";
.button:hover{
    -fx-text-fill: #fffff;
}

I have only had a month to program so far so please don't flame my code or my easy slip ups. 到目前为止,我只有一个月的编程时间,所以请不要随意编写代码或容易滑倒。 All thanks in advance for helping to solve the problem, i have been using scene builder and css style sheets for less than a day but i need to make progress fast as i have not been programming like the rest of my year have for almost 5 years. 在此先感谢所有帮助解决问题的人,我已经使用场景构建器和CSS样式表不到一天,但是我需要快速取得进展,因为我没有像过去一年中剩下的5年那样进行编程。

JavaFX CSS does not support the full CSS specification; JavaFX CSS不支持完整的CSS规范。 only a subset of it. 只是它的一个子集。 In particular, the only "@-Rules" listed as supported are @import and @font-face . 特别是, 列出的唯一支持的“ @ -Rules”是@import@font-face Consequently, the @charset rule you have on the first line is not supported. 因此,不支持第一行上的@charset规则。

Removing the first line of the CSS file (containing @charset ) will enable the CSS file to be parsed. 删除CSS文件的第一行(包含@charset )将使CSS文件能够被解析。

Also, you stated you want the text to turn white on hover: you need #ffffff (six ' f 's); 另外,您还说过您希望文本在悬停时变成白色:您需要#ffffff (六个' f '); you have #fffff (only five ' f 's). 您有#fffff (只有五个' f )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Javafx CSS解析错误 - Javafx CSS Parsing Error JavaFX CSS警告:CSS错误解析文件:...:预期LBRACE at - JavaFX CSS WARNING: CSS Error parsing file : … : Expected LBRACE at “线程“ AWT-EventQueue-0”中的异常java.lang.NullPointerException”。 我不知道我在做什么错 - “Exception in thread ”AWT-EventQueue-0“ java.lang.NullPointerException”. I have no clue what I'm doing wrong 解析错误; 我已经尝试过,无法弄清楚出了什么问题? - Parsing error; I have tried and can't figure out what's wrong? 在解析器中编译错误,认为我的输入文件有错误,但是不确定发生了什么错误 - Compile error in my parser, think I have my input file wrong, but unsure what did wrong 使用DOM解析XML文件,我做错了什么? - Parsing an XML file using DOM, what am I doing wrong? Java程序无法运行,我不知道出了什么问题 - Java program won't run, I've no clue what's wrong 我正在尝试随机播放或将输入字符串随机放置在图片上,但是我不知道要使用什么代码? - I am trying to shuffle or randomly place an input string on a picture but i have no clue on what code to use? Gradle with JavaFX:我做错了什么? - Gradle with JavaFX: What am I doing wrong? 我有一个错误:setOnItemClickListener 不能与微调器一起使用,这是怎么回事? - I have an error: setOnItemClickListener cannot be used with a spinner, what is wrong?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM