[英]JavaFX: Why does stage.setResizable(false) cause additional margins?
[英]Why does my javafx stage not want to load
這是java
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.stage.Stage;
public class mains extends Stage {
public static void main(String[] args) {
new JFXPanel();
Platform.runLater(new Runnable(){
@Override
public void run() {
new mains();
}
});
}
void go(){
new JFXPanel();
new mains().show();
}
public mains() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(
"LOL.fxml"));
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
try {
fxmlLoader.load();
} catch (Exception e) {
e.printStackTrace();
}
}
@FXML
private Button button;
@FXML
private Label label;
@FXML
void push(ActionEvent event) {
}
}
這是fxml http://pastebin.com/uzBrMRDV我得到一個加載異常,它說已經指定了Root。 如果我刪除setRoot(this); 它根本不會加載我對JFX感到非常沮喪...無論如何,是否有從控制器本身加載FXML文件(如舞台)的信息
刪除線
fxmlLoader.setRoot(this);
您的FXML將根定義為AnchorPane
(並且不能兩次設置根,這就是得到錯誤的原因)。
由於當前類是Stage
,並且FXMLLoader
加載AnchorPane
,因此您需要將加載的AnchorPane
在Scene
並在舞台中設置場景。 更換
fxmlLoader.load();
與
AnchorPane root = fxmlLoader.load();
Scene scene = new Scene(root); // optionally specify dimensions too
this.setScene(scene);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.