我正在使用JavaFX,我有一个奇怪的问题。以下代码位于继承Stage的类的构造函数中。代码正在进行中。
// this works fine, the chart is displayed
Scene scene = new Scene(lineChart, 1000, 600);
// table is not shown until I click on the window
Scene scene = new Scene(bidTable, 1000, 600);
this.setTitle("Auction chart");
this.setScene(scene);
我错了什么?单击窗口后,没有显示错误和包含内容的表格。在它只是一个白色的窗口之前。
编辑: 我删除了表格中的图表:
public class AuctionChart extends Stage {
private final TableView<Bid> bidTable = new TableView<Bid>();
private final TableColumn<Bid, String> bidColumn = new TableColumn<Bid, String>("Bid");
private final TableColumn<Bid, String> utilityColumn = new TableColumn<Bid, String>("Utility");
private final TableColumn<Bid, String> profitColumn = new TableColumn<Bid, String>("Profit");
private final NumberFormat fm = NumberFormat.getCurrencyInstance();
public AuctionChart() {
initialize();
bidTable.getColumns().addAll(bidColumn, utilityColumn, profitColumn);
Scene scene = new Scene(bidTable, 1000, 600);
this.setTitle("Auction chart");
this.setScene(scene);
}
public void setTowns(List<Town> towns) {
bidTable.setItems(FXCollections.observableArrayList(towns.get(0).getGebote()));
}
private void initialize() {
bidColumn.setCellValueFactory(cellData -> new SimpleStringProperty(fm.format(cellData.getValue().getBid())));
utilityColumn
.setCellValueFactory(cellData -> new SimpleStringProperty(fm.format(cellData.getValue().getUtility())));
profitColumn
.setCellValueFactory(cellData -> new SimpleStringProperty(fm.format(cellData.getValue().getProfit())));
}
}
启动:
AuctionChart stage = new AuctionChart();
stage.setTowns(towns);
stage.show();
答案 0 :(得分:0)
谢谢,这不是JavaFx问题。这是应用程序后端中并发线程的问题。