Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX - Is it possible to have a scroll bar in VBox?

Tags:

layout

javafx

i'am working a project that involves array of checkboxes. but i encounter a problem when i'm adding all the checkboxes in VBox. here is my screenshot below

http://i.stack.imgur.com/l0fw3.png

Other checkboxes cannot be viewed.

here is my code for checkboxes

public void initializeSenatorLists() {

    CheckBox []chckSenators = new CheckBox[senators.length];



    for(int s=0; s < senators.length; s++) {

        chckSenators[s] = new CheckBox(senators[s]);
        chckSenators[s].setStyle("-fx-font-size:15px;");
        chckSenators[s].setTextFill(Color.WHITE);
        senVbox.getChildren().add(chckSenators[s]);

    }

    for(CheckBox cbSen:chckSenators) {

       cbSen.setOnMouseClicked(new EventHandler<MouseEvent>() {

           @Override
           public void handle(MouseEvent event) {
               if(cbSen.isSelected()) {
                   senatorLimitVote++;


                      votedSenators.add(cbSen.getText());


               }else {
                   votedSenators.remove(cbSen.getText());
                   senatorLimitVote--;
             }
           }
       });


    }
}

What i want to do to my checkboxes is this http://i.stack.imgur.com/ODcDb.png

I hope you can help me.

like image 309
Novi Avatar asked Jun 22 '15 02:06

Novi


People also ask

What is a scroll pane JavaFX?

The ScrollPane allows the application to set the current, minimum, and maximum values for positioning the contents in the horizontal and vertical directions. These values are mapped proportionally onto the layoutBounds of the contained node.

Is ListView scrollable JavaFX?

The ListView class represents a scrollable list of items.

How do I add items to JavaFX virtualbox?

To add some buttons to the VBox use the getChildren(). add() function. Finally, create a scene and add the vbox to the scene and add the scene to the stage and call show() function to display the final results.


1 Answers

Try putting VBox inside a scrollPane. With this approach, you don't have to worry about setting the prefHeight and prefWidth attributes. You can use 'USE_COMPUTED_SIZE' for the VBox.

Example: VBox is added inside a ScrollPane, and various elements like HBox, Labels, and rectangles are added dynamically.

like image 65
Abhi Avatar answered Oct 24 '22 10:10

Abhi