0 Replies Latest reply: Mar 17, 2013 4:01 PM by 992571 RSS

    setMax() setVisibleAmount() of Table view's scrollbar are reset

    992571
      Hi,

      I have a table view which contains 166 rows of data. I want the table view's scroller to show only 15 rows.
      Basically, I've set scroller's properties like this: setMax(166) and setVisibleAmount(15)
      Unfortunately, it seems the properties previously set are later reset when displaying the table view ... Actually, I've added a listener to the scroller's value property and found out that the value's range is always between 0 and 1 and also the scroller shows more than the visible amount I had set. Normally, the value range should be between 0 and 166 and the table view should only show 15 rows. Am I right??

      Basically I've created a customTableView which extends TableView and add a listener to the skin in the contructor
      Here is a portion of my CustomTableView constructor, whichs
      1) Get a reference of the scrollbar from the table view skin.
      2) Add listener to the scroller's value property.
      3) Set properties max, visibleAmount, width and height
      skinProperty().addListener(new ChangeListener<Skin>()
      {
                  public void changed(ObservableValue<? extends Skin> pObservable, Skin pOldValue, Skin pNewValue)
               {
                      // get vitual flow node
                if (scbVertical == null)
                       {
                           ObservableList<Node> ovlChildren = ((SkinBase)pNewValue).getChildren();
                           
                           Node node;
                           
                           for (int i = 0, anz = ovlChildren.size(); i < anz && flow == null; i++)
                           {
                                node = ovlChildren.get(i);
                                
                                if (node instanceof VirtualFlow)
                                {
                                     flow = (VirtualFlow)node;
                                }
                           }
                            // get scroller reference
                           if (flow != null)
                           {        
                                   ovlChildren =flow.getChildrenUnmodifiable();
                                   for (int i = 0, anz = ovlChildren.size(); i < anz && scbVertical == null; i++)
                                   {
                                    node = ovlChildren.get(i);                           
                                    if (node instanceof ScrollBar && ((ScrollBar)node).getOrientation() == Orientation.VERTICAL)
                                    {
                                         scbVertical = (ScrollBar)node;
                                    }
                               }
                               
                              //add listener to scroller value
                               if (scbVertical != null)
                               {     
                                    scbVertical.setPrefSize(width, rowHeight*rowCount);
                                    scbVertical.setMaxSize(width, rowHeight*rowCount);                                                       
                                    scbVertical.setVisibleAmount(rowCount); //15
                                    scbVertical.setMax(getItems().size()); //166
      
                                    scbVertical.valueProperty().addListener(new ChangeListener() 
                                    {
                               public void changed(ObservableValue ov, Object oldValue, Object newValue) 
                                {
                                    System.out.println("max:"+scbVertical.getMax() +" scroll: " + scbVertical.getValue());
                               }
                           });                           
                                   }
                             }
                         }
                 }
           });
          }
      So my question is why setMax() and setVisibleAmount() are not taken into account()???

      Edited by: 989568 on 17-Mar-2013 14:00