2017-04-20 39 views
0

私は現在、このLayoutを作成しようとしています。JavaFx複数のレイアウト

私が使用することを試みた:

StackPane rootPane = new StackPane(); 
Scene scene = new Scene(rootPane,...); 
Pane pane1 = new Pane(); 
Pane pane2 = new Pane(); 
rootPane.getChildren().addAll(pane1,pane2); 

を私は直接その下にメニューバーと同様にテキストフィールドを作成してみましょうするのではなく、テキストフィールドがMenuBarによって隠されますよう、それは私を聞かせていません。

私の場合はどちらが必要なのか分かりません。私はvboxを見ました - これは私が必要としているものに似ていますが、最後の行に2つのテーブルを追加する方法が分かりません

私が方向を指すことができたら助けになるでしょう必要です。

答えて

2

StackPaneここでは適切な選択ではありません。子ノードをzオーダーで重ねるだけです。すべての組み込みのレイアウトペインの詳細な説明はtutorial on layoutsを読むことをお勧めしますが、1つのオプションはVBoxです。項目を最下行に配置するには、AnchorPaneを使用し、1つの項目は左に固定し、もう1つは右に固定します。ここで

は、このアプローチを使用してSSCCEです:

import javafx.application.Application; 
import javafx.geometry.Insets; 
import javafx.scene.Scene; 
import javafx.scene.control.Label; 
import javafx.scene.control.Menu; 
import javafx.scene.control.MenuBar; 
import javafx.scene.control.TextArea; 
import javafx.scene.layout.AnchorPane; 
import javafx.scene.layout.Priority; 
import javafx.scene.layout.VBox; 
import javafx.stage.Stage; 

public class LayoutExample extends Application { 

    @Override 
    public void start(Stage primaryStage) { 
     VBox root = new VBox(5); 
     root.setPadding(new Insets(5)); 

     MenuBar menuBar = new MenuBar(); 
     menuBar.getMenus().add(new Menu("File")); 

     TextArea textArea = new TextArea(); 
     VBox.setVgrow(textArea, Priority.ALWAYS); 

     AnchorPane bottomRow = new AnchorPane(); 
     Label table1 = new Label("Table 1"); 
     table1.setStyle("-fx-background-color: gray"); 
     table1.setMinSize(200, 200); 
     Label table2 = new Label("Table 2"); 
     table2.setStyle("-fx-background-color: gray"); 
     table2.setMinSize(200, 200); 

     AnchorPane.setLeftAnchor(table1, 0.0); 
     AnchorPane.setRightAnchor(table2, 0.0); 
     bottomRow.getChildren().addAll(table1, table2); 

     root.getChildren().addAll(menuBar, textArea, bottomRow); 

     Scene scene = new Scene(root, 800, 800); 
     primaryStage.setScene(scene); 
     primaryStage.show(); 
    } 

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

enter image description here

別の、同様のアプローチは、トップのメニューバーで、rootとしてテキスト領域をBorderPaneを使用することですセンター、およびアンカーペインを下部に表示します。

関連する問題