2013-06-04 90 views
1

我有這個帶有製表符的JavaFX代碼。你能告訴我怎麼可以設置標籤面板的位置始終在左側的主舞臺:如何在JavaFX中設置製表位

VBox stackedTitledPanes = createStackedTitledPanes(); 

     ScrollPane scroll = makeScrollable(stackedTitledPanes); 

     TabPane tabPane = new TabPane(); 
     BorderPane mainPane = new BorderPane(); 

     tabPane.setStyle("-fx-font-size: 12pt;"); // Set global size for the font 
     // Create Tabs 
     Tab tabA = new Tab(); 
     tabA.setText("Main Component"); 
     tabA.setStyle("-fx-font-size: 12pt;"); // Set size of the tab name 
     // Add something in Tab 
     StackPane tabA_stack = new StackPane(); 
     tabA_stack.setAlignment(Pos.CENTER); 
     tabA_stack.getChildren().add(scroll); 
     tabA.setContent(tabA_stack); 
     tabPane.getTabs().add(tabA); 

     Tab tabB = new Tab(); 
     tabB.setText("Second Component"); 
     tabB.setStyle("-fx-font-size: 12pt;"); // Set size of the tab name 
     // Add something in Tab 
     StackPane tabB_stack = new StackPane(); 
     tabB_stack.setAlignment(Pos.CENTER); 
     tabB_stack.getChildren().add(new Label("[email protected] B")); 
     tabB.setContent(tabB_stack); 
     tabPane.getTabs().add(tabB); 

     Tab tabC = new Tab(); 
     tabC.setText("Last Component"); 
     tabC.setStyle("-fx-font-size: 12pt;"); // Set size of the tab name 
     // Add something in Tab 
     StackPane tabC_vBox = new StackPane(); 
     tabC_vBox.setAlignment(Pos.CENTER); 
     tabC_vBox.getChildren().add(new Label("[email protected] C")); 
     tabC.setContent(tabC_vBox); 
     tabPane.getTabs().add(tabC); 

     mainPane.setCenter(tabPane); 

     mainPane.setPrefSize(395, 580); 
     mainPane.setLayoutX(850); 
     mainPane.setLayoutY(32); 

     scroll.setPrefSize(395, 580); 
     scroll.setLayoutX(850); 
     scroll.setLayoutY(32); 

     root.getChildren().add(mainPane); 

回答

3

更新

聽起來像是你想改變你stackedTitledPaneVBoxBorderPane。 所以這個代碼:

VBox stackedTitledPanes = new VBox(); 

變爲:

BorderPane stackedTitledPanes = new BorderPane(); 

然後,當你想要添加的節點,可以指定你想要把他們這部分(我把一個標籤,在中央窗格中的填料):

stackedTitledPanes.setLeft(mainPane); 
stackedTitledPanes.setCenter(new Label("Main Content")); 

老答案

這將使標籤左邊(我假設這是你在找什麼):

tabPane.setSide(Side.LEFT); 

TabPane Left side

+0

等我有我的,但無論如何謝謝你的寶貴例。我的想法是將選項卡面板(包含所有組件)始終放在主舞臺的左側,因爲當我調整主舞臺的大小時,位置將靜止。然後,我想要重新調整主舞臺的大小,以查看左側的選項卡面板。 –

+0

啊,我明白你在做什麼 - 我已經更新了我的答案,以更好地反映你的需求。 –

+0

是的,這是有效的。我還測試過將標籤面板放在主頁面的右側,但它不起作用。爲了將標籤面板放置在主舞臺的右側,是否還有其他事情需要更改? –

相關問題