【发布时间】:2017-05-02 22:33:00
【问题描述】:
我被“菜单屏幕”卡住了一段时间。
当我点击激活的客户面板时,它不会打开 CustomerDisplay.fxml
下面是我的代码;
public class MainApp extends Application {
protected Parent content;
private Stage primaryStage;
private Stage secondStage;
private CustomerController custCtrl;
private MaintainerController mntnCtrl;
private MachineryController machCtrl;
private String fxml="";
public static MainApp instance;
public MainApp () {
instance=this;
}
/**
* @param args
*/
public static void main(String[] args) {
launch(args);
}
public static MainApp getInstance() {
return instance;
}
@Override
public void start(Stage primaryStage) throws Exception {
initializePanel();
Scene scene = new Scene(content);
primaryStage.setResizable(false);
primaryStage.initStyle(StageStyle.UTILITY);
primaryStage.setScene(scene);
primaryStage.show();
}
private void initializePanel() throws IOException{
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("fxml/SimulatorDisplay.fxml"));
content = loader.load();
}
public void openCustomerPanel() throws IOException{
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("fxml/CustomerDisplay.fxml"));
content = loader.load();
}
public void openMaintainerPanel() throws IOException{
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("fxml/MaintainerDisplay.fxml"));
content = loader.load();
}
public void openMachineryPanel() throws IOException{
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("fxml/MachineryDisplay.fxml"));
content = loader.load();
}
}
public class SimulatorController implements Initializable{{
.
.
.
@FXML
public void clickCustomer (ActionEvent event) throws IOException{
log.info("Starting Customer Panel");
MainApp.getInstance().openCustomerPanel()**;
}
}
它打印 log.info("Starting Customer Panel") 但我看不到任何新窗口。 我想知道我们如何单击主屏幕上的按钮并显示新窗口。除非我们将其关闭,否则主屏幕将保持打开状态。我们需要定义新的阶段吗?
【问题讨论】:
-
您的方法
openXXXPanel只是加载一个FXML 文件并将对应于根元素的对象分配给变量content,但它们对新内容不做任何事情。您需要将当前场景的根设置为content(如果您想使用现有窗口),或者创建一个新的Stage(如果您想要一个新窗口)。 -
我创建了二级舞台,但是点击时它会在主屏幕上弹出主屏幕
-
好的,现在我明白了。感谢您的洞察力
标签: javafx controller