2016-08-09 1 views
1

Groupでパックされたノードの幅と高さを最大にする方法を理解しようとしています。私がGroupにパックしたい主な理由は、TranslateTransitiontreeViewからlistViewまで含めて戻したいということです。これを行うには、前後に移動されるダミーのノードが必要であり、そのノードには絶対配置が必要です。JavaFX:グループの子をレイアウトする方法

これによれば、私は以下のMWEで達成しようとしているGroupを使用する必要があります。

import javafx.application.Application; 
import javafx.geometry.Orientation; 
import javafx.scene.Group; 
import javafx.scene.Parent; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.control.Label; 
import javafx.scene.control.ListView; 
import javafx.scene.control.Menu; 
import javafx.scene.control.MenuBar; 
import javafx.scene.control.SplitPane; 
import javafx.scene.control.ToolBar; 
import javafx.scene.control.TreeItem; 
import javafx.scene.control.TreeView; 
import javafx.scene.layout.BorderPane; 
import javafx.scene.layout.VBox; 
import javafx.stage.Stage; 

import static javafx.collections.FXCollections.observableArrayList; 

public class MWE extends Application { 

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

    public void start(Stage primaryStage) throws Exception { 
     final VBox top = new VBox(new MenuBar(new Menu("File")), new ToolBar(new Button("button1"))); 
     final ToolBar bottom = new ToolBar(new Label("status")); 
     final SplitPane main = new SplitPane(new SplitPane(createSplitPaneWithTreeView()), new VBox()); 
     //main.setPrefSize(1920,1080); 
     final Group center = new Group(main); 
     main.setDividerPositions(0.40, 0.60); 
     BorderPane borderPane = new BorderPane(center, top, new Label(), bottom, null); 
     show(primaryStage, borderPane); 

    } 

    private SplitPane createSplitPaneWithTreeView() { 
     final TreeItem<String> root = new TreeItem<>("Foo"); 
     root.getChildren().addAll(new TreeItem<>("Item 1"), new TreeItem<>("Item 2")); 
     final TreeView<String> treeView = new TreeView<>(root); 
     SplitPane splitPane = new SplitPane(treeView, new ListView<>(observableArrayList("List item 1", "List item 2"))); 
     splitPane.setOrientation(Orientation.VERTICAL); 
     return splitPane; 
    } 

    private void show(Stage primaryStage, Parent parent) { 
     primaryStage.setScene(new Scene(parent, 1920, 1080)); 
     primaryStage.show(); 
    } 

} 

私は基本的にハードコード経由mainの推奨サイズを設定しないようにしたいです。私は、splitpaneのwidthProperty/heightPropertyをルートにバインドすることも可能ですが、それ以外の優雅な解決方法はありますか?

答えて

2

本当にグループを使用したい場合は、メインのSplitpaneのprefWidth/Heightを設定またはバインドする方法がありません。結局のところ、グループはコンテンツのprefSizeにサイズ変更されます。私はあなたがそれがunelegantそうのようなシーンの幅と高さにあなたのメインをバインドするために見つける理由が理解しない:

primaryStage.setScene(new Scene(borderPane, 1920, 1080)); 
main.prefHeightProperty().bind(primaryStage.getScene().heightProperty()); 
main.prefWidthProperty().bind(primaryStage.getScene().widthProperty()); 
primaryStage.show(); 

なぜそれは常に、あまりにもあなたの窓とのあなたが望む行動ではなく、道のサイズを変更するのだろうか?

関連する問題