java - Javafx 实际打开 Gui 示例的问题
问题描述
我在使用 javafx 时遇到问题(惊喜哈哈)。出于某种原因,我的代码似乎正在运行,但实际的 gui 从未出现在我的屏幕上,并且卡在右下角。当我在 Sample Controller 类中取出“可初始化的实现”时,就会显示 gui。我将非常感谢任何人可以给我的任何帮助!谢谢
主班
package application;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
示例控制器类
package application;
import java.awt.Label;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Alert;
import javafx.scene.control.ListView;
import javafx.scene.control.Alert.AlertType;
import javafx.stage.Popup;
import javafx.stage.Stage;
public class SampleController{
@FXML
private ListView<String>mainListView;
/**
* Initializing the class
*/
public void initialize(URL url, ResourceBundle rb) {
ObservableList<String>thisMainListView = FXCollections.observableArrayList("SPY","QQQ","Rus2000");
mainListView.setItems(thisMainListView);
}
}
解决方案
推荐阅读
- pandas - Pandas - 获取真/假索引
- google-sheets - 计算 Google 表格中缺少的必填字段的数量
- javascript - 我在 Angular 6 中使用 javascript 拖放事件。但在 ev.dataTransfer.effectAllowed = "copy"; 中面临问题
- python - builtins.AttributeError:'bytes' 对象在 python twisted 中没有属性'append'
- codeigniter-4 - Codeigniter 4 BadMethodCallException
- excel - VBA 是否有一种 psycopg2 风格的方式来连接到 PostgreSQL?
- sql - 带有谓词的 Postgresql EXCLUDE 约束:意外结果
- javascript - 在浏览器客户端中创建和下载 tar 存档而不使用服务器
- r - 在 r 中分别追加/增长列表元素
- php - 显示空白页的动态引导轮播