执行程序时,界面与场景构建器预览不同。这个问题让我抓狂。我该怎么做才能解决这个问题? Preview vs Result in execution FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.net.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?>
<AnchorPane prefHeight="425.0" prefWidth="242.0" styleClass="background" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="application.FirstController">
<children>
<Hyperlink layoutX="53.0" layoutY="357.0" text="Password dimenticata?" textFill="#33e7ff">
<stylesheets>
<URL value="@application.css" />
</stylesheets>
</Hyperlink>
<TextField fx:id="txtUsername" layoutX="15.0" layoutY="231.0" prefWidth="207.0" promptText="Username" />
<Separator layoutX="13.0" layoutY="345.0" prefHeight="4.0" prefWidth="200.0" />
<Separator layoutX="16.0" layoutY="220.0" prefWidth="200.0" />
<Button id="btnConferma" layoutX="14.0" layoutY="301.0" mnemonicParsing="false" prefWidth="99.0" text="Conferma" />
<Button id="btnAnnulla" layoutX="123.0" layoutY="301.0" mnemonicParsing="false" prefWidth="99.0" text="Annulla" />
<Text layoutX="92.0" layoutY="79.0" scaleX="3.5060922995036727" scaleY="2.63215859030837" strokeType="OUTSIDE" strokeWidth="0.0" text="CARLOAN">
<fill>
<Color blue="1.000" green="0.522" red="0.200" fx:id="x1" />
</fill>
</Text>
<Text fill="$x1" layoutX="189.0" layoutY="110.0" scaleX="1.3491931995059285" scaleY="1.313264806656877" strokeType="OUTSIDE" strokeWidth="0.0" text="V1.0" />
<TextArea id="areaTesto" editable="false" layoutX="19.0" layoutY="146.0" prefHeight="67.0" prefWidth="200.0" style=" " text="Benvenuto in CarLoan! Per favore effettua il login per utilizzare tutte le funzionalità del sistema." wrapText="true">
<stylesheets>
<URL value="@application.css" />
</stylesheets>
</TextArea>
<PasswordField fx:id="txtPassword" layoutX="15.0" layoutY="270.0" prefWidth="207.0" promptText="Password" />
</children>
<stylesheets>
<URL value="@application.css" />
</stylesheets>
</AnchorPane>
这是css:http://pastebin.com/NWTT8DAa
我在这个项目中使用了很多模式。特别是,我在主类包中有一个前端控制器,在执行视图交换的调度程序中。我发布了主要的classe和更改视图的方法:
主要课程:
package application;
import Eccezioni.Eccezione;
import presentation.tier.FrontController;
import javafx.application.Application;
import javafx.stage.Stage;
public class Main extends Application {
public static final Stage stage = new Stage();
@Override
public void start(Stage primaryStage) throws Eccezione {
try {
FrontController fc = null;
fc = FrontController.getInstance();
fc.handleRequest("openViewStart", null);
} catch (Exception e) {
throw new Eccezione("Impossibile lanciare il programma..");
}
}
public static void main(String[] args) {
launch(args);
}
}
这是调度方法:
private void apriViewStart() throws Eccezione {
try {
AnchorPane root = (AnchorPane) FXMLLoader.load(getClass().getResource("/application/Login.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("/application/application.css").toExternalForm());
Main.stage.setTitle("CarLoan 1.0");
Main.stage.setScene(scene);
Main.stage.show();
} catch (Exception e) {
throw new Eccezione("Impossibile caricare l'interfaccia.");
}
}
答案 0 :(得分:0)
我不知道为什么但是场景生成器预览和执行gui是不同的。要解决这个问题,我不得不在CSS代码中更改一些参数