我設計了一個場景製作器中帶有幾個按鈕的簡單場景。沒什麼特別對:小學舞臺改變場景大小
scenebuilder http://i41.tinypic.com/2zzlzls.jpg
我已經把那初級階段,它看起來OK我:
resizable http://i39.tinypic.com/8zpr8n.jpg
但現在,如果我改變的可調整大小的屬性主要舞臺爲假,場景在右側和底部增長:
resizable http://i41.tinypic.com/1zea6i0.jpg
爲什麼場景會在右側和底部增長?在我oppionion沒有什麼特別的就可以了:
@Override
public void start(Stage stage) throws Exception {
AnchorPane root = FXMLLoader.load(getClass().getResource("/fxml/start.fxml"));
Scene scene = new Scene(root);
stage.setResizable(false);
stage.setTitle("Game");
stage.setScene(scene);
stage.centerOnScreen();
stage.show();
}
的FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.net.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<AnchorPane fx:id="rootPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="310.0" prefWidth="320.0" xmlns:fx="http://javafx.com/fxml" fx:controller="bla.bla.bla.Controller">
<children>
<Button fx:id="btnNewGame" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" prefHeight="50.0" prefWidth="300.0" text="New Game" />
<Button fx:id="btnLoadGame" layoutX="10.0" layoutY="70.0" mnemonicParsing="false" prefHeight="50.0" prefWidth="300.0" text="Load Game" />
<Button fx:id="btnEditor" layoutX="10.0" layoutY="130.0" mnemonicParsing="false" prefHeight="50.0" prefWidth="300.0" text="Editor" />
<Button fx:id="btnProperties" layoutX="10.0" layoutY="190.0" mnemonicParsing="false" prefHeight="50.0" prefWidth="300.0" text="Properties" />
<Button fx:id="btnExit" layoutX="10.0" layoutY="250.0" mnemonicParsing="false" prefHeight="50.0" prefWidth="300.0" text="Exit" />
</children>
<stylesheets>
<URL value="@start.css" />
</stylesheets>
</AnchorPane>
而CSS:
#rootPane{
-fx-background-color: #333333;
}
.button{
-fx-background-color: #555555;
-fx-text-fill: silver;
-fx-background-radius: 0;
-fx-border-radius: 0;
-fx-border-color: #444444;
}
提前感謝!
請發佈fxml。 – Sebastian
我已經添加了fxml。 – Qri
在Sceen構建器中,將所有按鈕的pref寬度/高度更改爲計算(或max_size? - 現在不在FX構建器之前),將最大寬度/高度更改爲max_Value也應該這樣做。 – assylias