0

相关文件:(对任何格式表示歉意,已多次尝试使其正常工作)

如果文件不够,存储库在这里:https ://github.com/TheeNinja/StockLookupTool

stock_lookup_tool_main.fxml

<BorderPane fx:id="borderPane" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1" fx:controller="me.theeninja.stocklookuptool.gui.StockLookupToolApplicationController">
<top>
    ...    
</top>
<left />
<center /> 
</BorderPane>

stock_information_center.fxml

<GridPane xmlns="http://javafx.com/javafx"
        xmlns:fx="http://javafx.com/fxml"
        fx:controller="me.theeninja.stocklookuptool.gui.selection.StockSearchSelectionController"
        prefHeight="400.0" prefWidth="600.0"
        fx:id="stockInformationCenter">

</GridPane>

favorite_stocks_sidebar.fxml

<VBox xmlns:fx="http://javafx.com/fxml/1" fx:controller="me.theeninja.stocklookuptool.gui.selection.StockSearchSelectionController" fx:id="verticalStockList">
    ...
</VBox>

StockLookupTool.java(带有 start 方法的类)

public class StockLookupTool extends Application {


....
@Override
public void start(Stage stage) throws Exception {

    ...
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(getClass().getResource("/fxml/stock_lookup_tool_main.fxml"));
    Parent root = loader.load();

    Scene scene = new Scene(root, 250, 300);

    stage.setTitle(APPLICATION_TITLE);
    stage.setScene(scene);
    stage.setFullScreen(true);
    stage.show();
}
....
}

StockLookupToolApplicationController(stock_lookup_tool_main.fxml 的控制器)

public class StockLookupToolApplicationController {

...

@FXML public Label stockSearchLabel;
@FXML public Label newsLabel;
@FXML public Label settings;

@FXML public BorderPane borderPane;
@FXML public HBox topApplicationNavigation;

@FXML
public void handleStockSearchSelection() {
    logger.log(Level.INFO, "Setting GUI View to Stock Search");
    setView(StockSearchSelectionController.getInstance());
}

private void setView(Selection selection) {
    borderPane.setLeft(selection.getLeft());
    borderPane.setCenter(selection.getCenter());
    borderPane.setRight(selection.getRight());
    borderPane.setBottom(selection.getBottom());
}
}

StockSearchSelectionController.java(stock_information_center.fxml和 favorite_stocks_sidebar.fxml 的控制器)

public class StockSearchSelectionController implements Selection {

@FXML public Label favoriteStocksLabel;
@FXML public TextField addFavoriteStockInput;
@FXML public VBox verticalStockList;
@FXML public HBox addFavoriteStockInputContainer;
@FXML public GridPane stockInformationCenter;

@FXML
public void handleFavoriteStockInput(KeyEvent keyEvent) {
    if (keyEvent.getCode() == KeyCode.ENTER) {
    ...
        // makes visual changes to both stockInformationCenter AND verticalStockList, hence I need access to both fxml files (which is why this controls both).
    }
}

@Override
public Node getLeft() {
    return verticalStockList;
}

@Override
public Node getCenter() {
    return stockInformationCenter;
}
}

更多信息:

该接口Selection具有方法getLeft()getCenter()(以及其他不相关的方法)。这两个回报Node。在stock_lookup_tool_main.fxml中,在topBorderPane有一个按钮(在提供的代码片段中被剪掉),当按下时,调用handleStockSearchSelection()(这个方法调用确实发生了,我已经用记录器验证了它)。

现在有一个控制器,可以同时 stock_information_center.fxml控制和favorite_stocks_sidebar.fxml。该控制器实现Selection,进而实现getLeft()getCenter()getLeft()返回与 相关的 VBox 变量favorite_stocks_sidebar.fxml,同时getCenter()返回与 相关的 GridPane 变量stock_information_center.fxml。调用时handleStockSearchSelection(),borderPane 对象的左边部分设置为 VBox,中心设置为 GridPane。所有这些方法调用/操作都已被验证发生。但是,场景没有视觉上的变化。

我的问题是:为什么对边界窗格的这些更改没有在场景中直观地实现?stock_lookup_tool_main.fxml通过设置装载机的位置在场景 <-> 之间建立了联系。我还在stock_lookup_tool_main.fxml<-> 其控制器之间建立了一个链接,因此它们应该共享更改。我stock_lookup_tool_main.fxml通过在变量上调用 setLeft() 和 setCenter() 修改了控制器中的边框窗格(与 ID 相同的名称,borderPane)。然而,视觉上的场景并没有改变。

4

0 回答 0