[英]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.