This discussion is archived
2 Replies Latest reply: Nov 29, 2012 10:06 PM by 966041 RSS

tableview  with fixed number of rows

966041 Newbie
Currently Being Moderated
1) i am using a TableView and i want to have only 2 rows in it with 3 columns.
But at run time it shows multiple rows which i don't want. Can any one please help me how do i restrict the number of rows to two.

2) 2nd problem is that i am dispalying this tableview and a slider in a VBox which is inside a scrollpane and this scrollpane is at left of the SpitPane(Horizontal).
But when i want to resize(scroll towards right) at run time although the scroll is moving right but the VBox is not resized. I tried to put the Vbox in a HBox and set the Horizontal growth and still i fail.

Please help me.

Thanks in advance.
  • 1. Re: tableview  with fixed number of rows
    jsmith Guru
    Currently Being Moderated
    Please provide some simple executable code. Thanks.
  • 2. Re: tableview  with fixed number of rows
    966041 Newbie
    Currently Being Moderated
    Here is the code for the TableView.
    import javafx.collections.FXCollections;
    import javafx.collections.ObservableList;
    import javafx.scene.control.TableColumn;
    import javafx.scene.control.TableView;
    import javafx.scene.control.cell.PropertyValueFactory;
    public class TableController {
        private static TableView tableView;
        static String[] colorModel={"Red","Green","Blue",
         * Constructs the TableView with three columns.
         * Default setting is for RGB space.
        public TableController() {        
            //For Data column
            TableColumn dataColValue = new TableColumn();
            dataColValue.setCellValueFactory(new PropertyValueFactory("value"));        
            //First column
            TableColumn firstCol = new TableColumn();
            firstCol.setCellValueFactory(new PropertyValueFactory("c1"));        
            //2nd column
            TableColumn secondCol = new TableColumn();
            secondCol.setCellValueFactory(new PropertyValueFactory("c2"));
            //Last  column
            TableColumn lastCol = new TableColumn();
            lastCol.setCellValueFactory(new PropertyValueFactory("c3"));        
            tableView = new TableView();
            //Enabling editing
         * @return the TableView Object.
        public static TableView getTable(){
            return tableView;
         * Gets the 3 parameters and sets them in the table format in 3 col.s  
         * @param forValue : for what value of the component. Ex: 3 of Red in RGB
         * @param noOfPixels : No. of pixels for "forValue"
         * @param model : to identify the color model.
         * col: 0-RGB,1-HSV,2-XYZ,3-YIQ. 
         * Note: Used by SliderController class.
        public static void setTable(int forValue,int[] noOfPixels,int model){
            //System.out.println("Table: model="+model);
            //set the col name.
            //set the row values with the "forvalue" and "noOfPixels" and dataCol value.
            final ObservableList<Data> data = FXCollections.observableArrayList(
                new Data("Value",forValue, forValue,forValue),
                new Data("No. Of Pixels", noOfPixels[0],noOfPixels[1],noOfPixels[2])                
        public static class Data{
            private StringProperty value;
            private StringProperty c1;
            private StringProperty c2;
            private StringProperty c3;
            private Data(String dataColValue,int c1, int c2,int c3){
                this.value = new SimpleStringProperty(dataColValue);
                this.c1 = new SimpleStringProperty(Integer.toString(c1));
                this.c2 = new SimpleStringProperty(Integer.toString(c2));
                this.c3 = new SimpleStringProperty(Integer.toString(c3));
            public StringProperty valueProperty() { return value; }
            public StringProperty c1Property() { return c1; }
            public StringProperty c2Property() { return c2; }
            public StringProperty c3Property() { return c3; }
    The 2nd problem is that the the Vbox inside a scrollpane which is in left part of the SplitPane is not horizontally
    Although i can move the divider of the splitpane left and right and the right side contents are flexible with respect to the movement of the splitpane but the left side is fixed.

    Here is the fxml code:

    <SplitPane id="splitPane" fx:id="mainSplitPane" dividerPositions="0.3105263157894737" focusTraversable="true" prefHeight="627.0" prefWidth="952.0" AnchorPane.bottomAnchor="-1.0" AnchorPane.leftAnchor="-1.0" AnchorPane.rightAnchor="-1.0" AnchorPane.topAnchor="74.0">
            <AnchorPane fx:id="leftPane" focusTraversable="true" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
                <ScrollPane fx:id="leftScrollPane" prefHeight="640.0" prefWidth="292.0" vbarPolicy="NEVER" AnchorPane.bottomAnchor="-1.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="1.0">
                    <AnchorPane id="Content" fx:id="leftAnchorPane" minHeight="0.0" minWidth="0.0" prefHeight="623.0" prefWidth="291.0">
                        <VBox id="leftMainVBox" fx:id="imageInfo" prefHeight="622.9998779296875" prefWidth="291.0" style="&#10;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
                           ............some children-------


  • Correct Answers - 10 points
  • Helpful Answers - 5 points