Mailingliste - Einträge 2005


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [qftestJUI] How to change the name of a column of a JTable


  • Subject: Re: [qftestJUI] How to change the name of a column of a JTable
  • From: Gregor Schmid <Gregor.Schmid@?.de>
  • Date: Wed, 12 Oct 2005 07:12:02 -0000

Hi Philippe,

basically your approach is fine. There are two mistakes however:

1) Your resolver treats cells and column headers which is why you are
seeing the weird result for your cells. You need to modify the code:

public String getItemName(Object object, Object object1, Object
object2) {
  if (object2 != null) {
        // Table cell, not my job
        return null;
  } else {
        ...

2) If you look at the table in manual section 22.1.3 you'll see that
   the resolver for table column has to be registered on the table
   header, not the table itself. So change install to register on
   javax.swing.JTableHeader and modify your code


if ((object instanceof JTableHeader)
    && (((JTableHeader) object).getTable instanceof GridDwcTable))
    GridDwcTable dw = (GridDwcTable) ((JTableHeader) object).getTable();


That should give you the desired result. If it doesn't add some
println statements or whatever logging you're using to find out
whether the method is called as expected etc.

Best regards,
    Greg

"Philippe Gaudin" <Philippe.Gaudin@?.com> writes:

>    Hi !
>
>
>
>    I have some problems writing an ItemNameResolver to change the name of
>    cells of JTables.
>
>
>
>    By default, the ids of cells are something like .table@label&1 where
>    label is the label in the header of the column.
>
>
>
>    What I would like is to provide another name for the columns (i.e. a
>    name which is not dependant of the language, position of the column in
>    the table).
>
>
>
>    I tried to create an ItemNameResolver in Java ( a GridDwcTable extends
>    JTable ) :
>
>
>
>    ----------------------------------------------------------------------
>    -------------------
>
>      public static void install() {
>
>    ResolverRegistry.instance().registerItemNameResolver("javax.swing.JTab
>    le", instance);
>      }
>
>       public String getItemName(Object object, Object object1, Object
>    object2) {
>         if (GridDwcTable.class.isAssignableFrom(object.getClass())) {
>            GridDwcTable dw = (GridDwcTable) object;
>            int colNbr = ((Integer) object1).intValue();
>            String colName = dw.getDwColName(colNbr);
>
>
>
>            String result = colName + "&" + object2;
>            return result;
>          }
>          else {
>            return null;
>          }
>
>    }
>
>    ----------------------------------------------------------------------
>    -------------------
>
>
>
>    Using this resolver, the Component Id of the cell is still like
>    table@label&1...
>
>
>
>    BUT the TEXT of the cell is my returned result for example
>    COLUMN_NAME&1
>
>
>
>    My questions :
>
>      * what am I doing wrong ?
>      * how can I customize the column name of a cell of a JTable in an
>        ItemNameResolver (or in any other resolver) ?
>
>
>
>    I'm using qfTestJUI 1.08.4 (build 1582)
>
>
>
>
>
>    Thanks in advance for your help !!
>
>
>
>    Philippe

--
Gregor Schmid                                Gregor.Schmid@?.de
Quality First Software GmbH                     http://www.qfs.de
Tulpenstr. 41                                Tel: +49 8171 919870
DE-82538 Geretsried                          Fax: +49 8171 919876


Videos Downloads Dokumentation Kaufen Gratis Testen