1

SplitPane2個AnchorPane(左右)持っています。があり、Labelそれぞれに一列に並んでいます。左側に、右側にバインドする必要があり、それらの間でストレッチする必要があります。Leftは の左部分にバインドする必要があります。TextFieldButtonAnchorPaneLabelAnchorPaneButtonTextFieldAnchorPaneSplitPane

私のコードは機能しますが、しばらくしてから仕切りを移動するButtonsと、バインディングから飛び出しSplitPaneます。 AnchorPane幅 バインド先SplitPane.Divider, Label, TextField,Buttonバインド先AnchorPane. 手伝って頂けますか?私の英語でごめんなさい。

    import javafx.application.Application;
    import javafx.beans.binding.DoubleBinding;
    import javafx.beans.value.ObservableValue;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.control.SplitPane;
    import javafx.scene.control.TextField;
    import javafx.scene.layout.AnchorPane;
    import javafx.stage.Stage;

    public class Main extends Application {

        public static void main(String[] args) {
            Application.launch(args);
        }

        @Override
        public void start(Stage stage) {
            stage.setTitle("BackUpManager");
            AnchorPane root = new AnchorPane();
            Scene scene = new Scene(root, 800,600);

            SplitPane splitPane = new SplitPane();
            splitPane.setLayoutY(50);
            splitPane.prefWidthProperty().bind(root.widthProperty());
            splitPane.prefHeightProperty().bind(root.heightProperty().subtract(50));

            AnchorPane rRoot = new AnchorPane();
            AnchorPane wRoot = new AnchorPane();

            splitPane.getItems().addAll(rRoot,wRoot);

            rRoot.setMinWidth(200);
            rRoot.prefWidthProperty().bind(splitPane.getDividers().get(0).positionProperty());
            Button rBrowse = new Button();
            rRoot.getChildren().add(rBrowse);
            rBrowse.setText("Browse");
            DoubleBinding db0 = rRoot.widthProperty().subtract(55);
            db0.addListener(new javafx.beans.value.ChangeListener<Number>() {
                public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
                    rBrowse.setLayoutX(db0.getValue());
                }});
            Label rLabel = new Label("Reserve dir");
            rRoot.getChildren().add(rLabel);
            rLabel.setLayoutY(3);
            TextField rPath = new TextField();
            rRoot.getChildren().add(rPath);
            rPath.setLayoutX(60);
            rPath.prefWidthProperty().bind(rRoot.widthProperty().subtract(115));        

            wRoot.prefWidthProperty().bind(splitPane.widthProperty().subtract(splitPane.getDividers().get(0).positionProperty()));
            wRoot.setMinWidth(200);
            Button wBrowse = new Button();
            wRoot.getChildren().add(wBrowse);
            wBrowse.setText("Browse");
            DoubleBinding db1 = wRoot.widthProperty().subtract(55);
            db1.addListener(new javafx.beans.value.ChangeListener<Number>() {
                public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
                    wBrowse.setLayoutX(db1.getValue());
                }});
            Label wLabel = new Label("Working dir");
            wRoot.getChildren().add(wLabel);
            wLabel.setLayoutY(3);
            TextField wPath = new TextField();
            wRoot.getChildren().add(wPath);
            wPath.setLayoutX(64);
            wPath.prefWidthProperty().bind(wRoot.widthProperty().subtract(119));

            rBrowse.setOnAction(new EventHandler<ActionEvent>() {
                @Override
                public void handle (ActionEvent e) {
                    System.out.println("Called");
                }
            });

            root.getChildren().addAll(splitPane);
            stage.setScene(scene);
            stage.show();
        }
    }
4

0 に答える 0