4 Replies Latest reply on Feb 14, 2013 10:22 PM by charlymoon-JavaNet

    TableView with customized cell factories

    charlymoon-JavaNet
      when using table cell factories to show (let's say) 35000 rows an using buttons to navigate with listeners like:
      /**
           * Coloca el foco en el registro anterior al que lo tenga
           *
           * @param evt Botón que solicita el evento
           */
          @FXML
          private void btnAnteriorAction(ActionEvent evt) {
              tblResultados.getSelectionModel().selectPrevious();
              tblResultados.scrollTo(tblResultados.getSelectionModel().getSelectedIndex());
          }
      if i go to the end and then i go to the previous... it is sloooooooooow, cose my cell factories are being called from the first register to the last one painted... ¿Is there a way to make this more eficiently?
      Greetings
        • 1. Re: TableView with customized cell factories
          charlymoon-JavaNet
          By the way... selectFirst() and selectLast() works incredible fine, the trouble is when you want to reach any row near the end, but not the end.
          • 2. Re: TableView with customized cell factories
            Jonathan Giles-Oracle
            This is resolved in JavaFX 8.0: http://javafx-jira.kenai.com/browse/RT-26363

            -- Jonathan
            • 3. Re: TableView with customized cell factories
              charlymoon-JavaNet
              From your answer i can see that:
              1.- this is not going to be resolved for JavaFX 2.x
              2.- Is going to be "realesed" on some date this year (is there a date for Java8?)
              3.- I can't (or do i?) use netBeans 7.2 to solve it
              I wonder this 3 reasons cause we have a delivery date for the program on June this year... and that date can't be move (since a legal term ocurrs and has to be with the release of the program)... so i should drop the development??? i don't think taking out a product based on a unrealeased java version can be a good idea.
              • 4. Re: TableView with customized cell factories
                charlymoon-JavaNet
                work around:
                /*
                 * To change this template, choose Tools | Templates
                 * and open the template in the editor.
                 */
                package mx.gob.scjn.iusjfx.presentacion.utils;
                
                import com.sun.javafx.scene.control.skin.TableViewSkin;
                import com.sun.javafx.scene.control.skin.VirtualContainerBase;
                import com.sun.javafx.scene.control.skin.VirtualFlow;
                import java.util.Set;
                import javafx.geometry.Orientation;
                import javafx.scene.Node;
                import javafx.scene.control.IndexedCell;
                import javafx.scene.control.ScrollBar;
                import javafx.scene.control.TableView;
                
                /**
                 *
                 * @author charly
                 */
                public class IUSTableView extends TableView
                {
                    protected double rowHeight;
                    @Override
                    public void scrollTo(int registro){
                        TableViewSkin skin = (TableViewSkin)getSkin();
                        VirtualFlow vf = null;
                        for(Node node : skin.getChildren()){
                            if(node instanceof VirtualFlow){
                                vf = (VirtualFlow)node;
                            }
                        }
                        ScrollBar bar=null;
                        for(Node node : vf.getChildrenUnmodifiable()){
                            if(node instanceof ScrollBar){
                                bar=(ScrollBar)node;
                                if(Orientation.VERTICAL== bar.getOrientation()){
                                    bar.valueProperty().set((double)(
                                            ((double)registro/(double)(getItems().size()-1))
                                            *bar.getMax()));
                                }
                            }
                        }
                    }
                
                    public double getRowHeight() {
                        return rowHeight;
                    }
                
                    public void setRowHeight(double rowHeight) {
                        this.rowHeight = rowHeight;
                    }
                    
                }
                work just if all cells are the same height.
                Greetings