2017-03-20 22 views
0

BorderPaneの右側にVBoxを使用して折りたたみ可能なサイドバーを作成しました。このサイドバーでは、選択したクラス(気泡と呼ばれる)のソースコードをリストとして表示しています。各バブルの幅は300ピクセル、高さは700ピクセルです。しかし、サイドバーに新しいバブルを追加すると、リストの他のバブルが縮小し始めました。これの代わりに、スクロールバーをのサイドバーVBoxに入れたいと思います。どのように私はこれを達成することができる?JavaFxでスクロール可能なVBoxを作成

void initSideBarActions() { 
    sideBar = new SideBarView(borderPane); 
    borderPane.setRight(sideBar); 

    String sourceCode = "public class FXMLDocumentController implements Initializable {\n" + 
      " @FXML\n" + 
      " AnchorPane apMain;\n" + 
      "\n" + 
      " @Override\n" + 
      " public void initialize(URL url, ResourceBundle rb)\n" + 
      " {\n" + 
      "   BubbleShape bs = new BubbleShape(\"Hello world!\");\n" + 
      "   bs.setLayoutX(50.0);\n" + 
      "   bs.setLayoutY(50.0);\n" + 
      "\n" + 
      "   BubbleShape bs2 = new BubbleShape(\"Bye world!\");\n" + 
      "   bs2.setLayoutX(400);\n" + 
      "   bs2.setLayoutY(400);\n" + 
      "   apMain.getChildren().addAll(bs, bs2);\n" + 
      " }\n" + 
      "}"; 

    BubbleView bubble1 = new BubbleView(sourceCode, "SampleClassOne"); 
    BubbleView bubble2 = new BubbleView(sourceCode, "SampleClassTwo"); 
    BubbleView bubble3 = new BubbleView(sourceCode, "SampleClassThree"); 

    sideBar.addNewBubble(bubble1); 
    sideBar.addNewBubble(bubble2); 
    sideBar.addNewBubble(bubble3); 
} 

ここではスクリーンショットです:

Screenshot of the current version

、ここでは、.fxmlファイルです:

<?xml version="1.0" encoding="UTF-8"?> 

<?import javafx.scene.layout.BorderPane?> 
<?import javafx.scene.layout.Pane?> 
<?import javafx.scene.control.ToolBar?> 
<?import javafx.scene.control.Button?> 
<?import javafx.scene.layout.VBox?> 
<?import javafx.scene.control.Slider?> 
<?import javafx.scene.control.Label?> 
<?import javafx.scene.layout.HBox?> 
<?import javafx.scene.control.ScrollPane?> 
<?import javafx.scene.control.ScrollPane?> 
<?import javafx.scene.control.ColorPicker?> 
<?import javafx.scene.layout.StackPane?> 

<BorderPane fx:id="borderPane" fx:controller="com.kaanburaksener.octoUML.src.controller.ClassDiagramController" xmlns:fx="http://javafx.com/fxml"> 
    <top> 
     <VBox> 
      <ToolBar fx:id="aToolBar" orientation="HORIZONTAL"> 
       <HBox fx:id="umlBox"> 
        <Button text="Create" fx:id="createBtn"/> 
        <Button text="Enumeration" fx:id="enumBtn"/> 
        <Button text="Package" fx:id="packageBtn"/> 
        <Button text="Edge" fx:id="edgeBtn"/> 
        <Button text="Draw" fx:id="drawBtn"/> 
       </HBox> 
       <HBox fx:id="utilBox"> 
        <Button text="Select" fx:id="selectBtn"/> 
        <Button text="Move" fx:id="moveBtn"/> 
       </HBox> 
       <HBox fx:id="undoBox"> 
        <Button text="Delete" fx:id="deleteBtn"/> 
        <Button text="Undo" fx:id="undoBtn"/> 
        <Button text="Redo" fx:id="redoBtn"/> 
       </HBox> 
       <HBox fx:id="recognizeBox"> 
        <Button text="Source Code" fx:id="sourceCodeBtn"/> 
        <Button text="Recognize" fx:id="recognizeBtn"/> 
        <Button text="Voice" fx:id="voiceBtn"/> 
       </HBox> 
      </ToolBar> 
     </VBox> 
    </top> 
    <bottom> 
     <StackPane fx:id="infoPane"> 
      <ToolBar fx:id="zoomPane"> 
       <Pane HBox.hgrow="ALWAYS" /> 
       <VBox alignment="CENTER"> 
        <Slider fx:id="zoomSlider" min="10" max="200" value="100"/> 
        <Label fx:id="zoomLabel" text="Zoom" /> 
       </VBox> 
       <Pane HBox.hgrow="ALWAYS" /> 
      </ToolBar> 
      <ColorPicker fx:id="colorPicker" StackPane.alignment="CENTER_LEFT"/> 
      <Label fx:id="serverLabel" StackPane.alignment="CENTER_RIGHT"/> 
     </StackPane> 
    </bottom> 
    <center> 
     <ScrollPane fx:id="scrollPane" pannable="true" BorderPane.alignment="CENTER"> 
      <content> 
       <Pane fx:id="drawPane" prefHeight="8000.0" prefWidth="8000.0"> 
       </Pane> 
      </content> 
     </ScrollPane> 
    </center> 
</BorderPane> 

私はこの質問(How to create a scrollable panel of components in JavaFX?)を読んでいる場合でも、私は私のプロジェクトに解決策を適用できませんでした。

答えて

4

スクロールペインにサイドバーをラップするだけです。縦方向にしかスクロールできないようにするには、setFitToWidth(true)に電話してください。

sideBar = new SideBarView(borderPane); 

ScrollPane sideBarScroller = new ScrollPane(sideBar); 
sideBarScroller.setFitToWidth(true); 

borderPane.setRight(sideBarScroller); 
関連する問題