pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jérôme Serré <jerome.michel.se...@gmail.com>
Subject RE: To build a TablePane
Date Fri, 22 Oct 2010 16:42:17 GMT
The last question Greg.
When I create a new Component, how I do to display it in the windows.

Thank you
Jérôme

-----Message d'origine-----
De : Greg Brown [mailto:gkbrown@mac.com] 
Envoyé : vendredi 22 octobre 2010 14:37
À : user@pivot.apache.org
Objet : Re: To build a TablePane

I think I see the problem. When an instance of TablePane.Row is created, it
is empty (i.e. it has length 0). Since TablePane#setCellComponent() calls
update() on the row, you get an IndexOutOfBounds exception because there is
no cell at that index to update.

I had actually forgotten about this method, and it should probably be
removed from the platform for this reason. The best way to construct a
TablePane dynamically is to create all of your columns, then use the add()
method to create and populate the rows:


    TablePane tablePane = new TablePane();

    // Add 3 columns
    TablePane.ColumnSequence columns = tablePane.getColumns();
    columns.add(new TablePane.Column());
    columns.add(new TablePane.Column());
    columns.add(new TablePane.Column());
    
    TablePane.RowSequence rows = tablePane.getRows();

    for (int i = 0; i < ROW_COUNT; i++) {
        TablePane.Row row = new TablePane.Row();
        rows.add(row);
        
        for (int j = 0; j < columns.getLength(); j++) {
            // Add cell for column j
        }
    }

G

On Oct 22, 2010, at 4:29 AM, Jérôme Serré wrote:

> Hello,
> 
> 
> 
> I try to build a TablePane dynamically but it doesn’t work !
> 
> As if the table had no rows and no columns.
> 
> Someone could help me to find the error.
> 
> Thanks
> 
> 
> 
> 
> 
> Trace : 
> 
> nbCol: 3
> 
> nbLigne: 4
> 
> Rows: 4
> 
> Columns: 3
> 
> i: 2
> 
> j: 1
> 
> and the error : 
> 
> java.lang.IndexOutOfBoundsException: index 1 out of bounds.
> 
>                        at
>
org.apache.pivot.collections.ArrayList.verifyIndexBounds(ArrayList.java:577)
> 
>                        at
> org.apache.pivot.collections.ArrayList.get(ArrayList.java:346)
> 
>                        at
> org.apache.pivot.wtk.TablePane$Row.update(TablePane.java:221)
> 
>                        at
> org.apache.pivot.wtk.TablePane.setCellComponent(TablePane.java:914)
> 
>                        at
> applet.Principale.buildHautDroit(Principale.java:552)
> 
> 
> 
> TablePane hautDroit = new TablePane();
> 
> int nbCol = cb.getNbColonne();
> 
> int nbLigne = cb.getNbLigne();
> 
> 
> 
> System.out.println("nbCol: " + nbCol);
> 
> System.out.println("nbLigne: " + nbLigne);
> 
> 
> 
> for (int j=0; j<nbCol; j++) { hautDroit.getColumns().add(new
> TablePane.Column(1, true)); }
> 
> for (int i=0; i<nbLigne; i++) { hautDroit.getRows().add(new
TablePane.Row(1,
> true)); }
> 
> 
> 
> System.out.println("Rows: " + hautDroit.getRows().getLength());
> 
> System.out.println("Columns: " + hautDroit.getColumns().getLength());
> 
> 
> 
> ImageView im;
> 
> for (int i=0; i<nbLigne; i++) {
> 
> for (int j=0; j<nbCol; j++) {
> 
>              if (cb.getCase(i, j)!=null) {
> 
> System.out.println("i: " + i);
> 
>                     System.out.println("j: " + j);
> 
>                    im = new ImageView(Image.load(cb.getCase(i,
> j).getVin().getImgCouleur()));
> 
>                    im.getUserData().put(String.valueOf(i) +
> String.valueOf(j), cb.getCase(i, j));
> 
>       ==è Error    hautDroit.setCellComponent(i, j, im);          
> 
>              }
> 
>       }
> 
> }
> 
> 
> 
> --
> 
> Cordialement
> 
> Jérôme Serré
> 
> 
> 
> 


Mime
View raw message