TableSorter

I have a problem with TableSorter. I am pretty much using the version supplied on the Sun site.
When I click the headers, the table reorganises itself fine on the screen.
However when I double click on them using a method within the JTable the row which appears is the one at that position before the tables were sorted. I am sure it is something to do with the TableModel but I can't figure out what. Anyone had a problem similar to this in the past?
Any feedback welcome.
Thanks,
Paul

I have a problem with TableSorter. I am pretty much using the version supplied on the Sun site.
When I click the headers, the table reorganises itself fine on the screen.
However when I double click on them using a method within the JTable the row which appears is the one at that position before the tables were sorted. I am sure it is something to do with the TableModel but I can't figure out what. Anyone had a problem similar to this in the past?
Any feedback welcome.
Thanks,
Paul

Similar Messages

  • TableSorter errors when adding new data

    so here is the deal:
    I am using the TableSorter.java helper class with DefaultTableModel
    from: http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
    It works great when the data is static and I get it for the first time. however, occationally, when adding new data I get a NullPointerException error.
    in use:
    DefaultTableModel.addRow()
    DefaultTableModel.removeRow() and
    DefaultTableModel.insertRow() methods.
    Error:
    java.lang.ArrayIndexOutOfBoundsException: 5
         at com.shared.model.TableSorter.modelIndex(TableSorter.java:294)
         at com.shared.model.TableSorter.getValueAt(TableSorter.java:340)
         at javax.swing.JTable.getValueAt(Unknown Source)
         at javax.swing.JTable.prepareRenderer(Unknown Source)...
    code problem I:
        public Object getValueAt(int row, int column)
            return tableModel.getValueAt(modelIndex(row), column);
        }code problem II:
        public int modelIndex(int viewIndex)
                 return getViewToModel()[viewIndex].modelIndex;     
        }TableSroter class:
    package com.shared.model;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.util.List;
    import javax.swing.*;
    import javax.swing.event.TableModelEvent;
    import javax.swing.event.TableModelListener;
    import javax.swing.table.*;
    * TableSorter is a decorator for TableModels; adding sorting
    * functionality to a supplied TableModel. TableSorter does
    * not store or copy the data in its TableModel; instead it maintains
    * a map from the row indexes of the view to the row indexes of the
    * model. As requests are made of the sorter (like getValueAt(row, col))
    * they are passed to the underlying model after the row numbers
    * have been translated via the internal mapping array. This way,
    * the TableSorter appears to hold another copy of the table
    * with the rows in a different order.
    * <p/>
    * TableSorter registers itself as a listener to the underlying model,
    * just as the JTable itself would. Events recieved from the model
    * are examined, sometimes manipulated (typically widened), and then
    * passed on to the TableSorter's listeners (typically the JTable).
    * If a change to the model has invalidated the order of TableSorter's
    * rows, a note of this is made and the sorter will resort the
    * rows the next time a value is requested.
    * <p/>
    * When the tableHeader property is set, either by using the
    * setTableHeader() method or the two argument constructor, the
    * table header may be used as a complete UI for TableSorter.
    * The default renderer of the tableHeader is decorated with a renderer
    * that indicates the sorting status of each column. In addition,
    * a mouse listener is installed with the following behavior:
    * <ul>
    * <li>
    * Mouse-click: Clears the sorting status of all other columns
    * and advances the sorting status of that column through three
    * values: {NOT_SORTED, ASCENDING, DESCENDING} (then back to
    * NOT_SORTED again).
    * <li>
    * SHIFT-mouse-click: Clears the sorting status of all other columns
    * and cycles the sorting status of the column through the same
    * three values, in the opposite order: {NOT_SORTED, DESCENDING, ASCENDING}.
    * <li>
    * CONTROL-mouse-click and CONTROL-SHIFT-mouse-click: as above except
    * that the changes to the column do not cancel the statuses of columns
    * that are already sorting - giving a way to initiate a compound
    * sort.
    * </ul>
    * <p/>
    * This is a long overdue rewrite of a class of the same name that
    * first appeared in the swing table demos in 1997.
    * @author Philip Milne
    * @author Brendon McLean
    * @author Dan van Enckevort
    * @author Parwinder Sekhon
    * @version 2.0 02/27/04
    public class TableSorter extends AbstractTableModel
        protected TableModel tableModel;
        public static final int DESCENDING = -1;
        public static final int NOT_SORTED = 0;
        public static final int ASCENDING = 1;
        private static Directive EMPTY_DIRECTIVE = new Directive(-1, NOT_SORTED);
        public static final Comparator COMPARABLE_COMAPRATOR = new Comparator()
            public int compare(Object o1, Object o2)
                return ((Comparable) o1).compareTo(o2);
        public static final Comparator LEXICAL_COMPARATOR = new Comparator()
            public int compare(Object o1, Object o2)
                return o1.toString().compareTo(o2.toString());
        private Row[] viewToModel;
        private int[] modelToView;
        private JTableHeader tableHeader;
        private MouseListener mouseListener;
        private TableModelListener tableModelListener;
        private Map columnComparators = new HashMap();
        private List sortingColumns = new ArrayList();
        public TableSorter()
            this.mouseListener = new MouseHandler();
            this.tableModelListener = new TableModelHandler();
        public TableSorter(TableModel tableModel)
            this();
            setTableModel(tableModel);
        public TableSorter(TableModel tableModel, JTableHeader tableHeader)
            this();
            setTableHeader(tableHeader);
            setTableModel(tableModel);
        private void clearSortingState()
            viewToModel = null;
            modelToView = null;
        public TableModel getTableModel()
            return tableModel;
        public void setTableModel(TableModel tableModel)
            if (this.tableModel != null)
                this.tableModel.removeTableModelListener(tableModelListener);
            this.tableModel = tableModel;
            if (this.tableModel != null)
                this.tableModel.addTableModelListener(tableModelListener);
            clearSortingState();
            fireTableStructureChanged();
        public JTableHeader getTableHeader()
            return tableHeader;
        public void setTableHeader(JTableHeader tableHeader)
            if (this.tableHeader != null)
                this.tableHeader.removeMouseListener(mouseListener);
                TableCellRenderer defaultRenderer = this.tableHeader.getDefaultRenderer();
                if (defaultRenderer instanceof SortableHeaderRenderer)
                    this.tableHeader.setDefaultRenderer(((SortableHeaderRenderer) defaultRenderer).tableCellRenderer);
            this.tableHeader = tableHeader;
            if (this.tableHeader != null)
                this.tableHeader.addMouseListener(mouseListener);
                this.tableHeader.setDefaultRenderer
                        new SortableHeaderRenderer(this.tableHeader.getDefaultRenderer())
        public boolean isSorting()
            return sortingColumns.size() != 0;
        private Directive getDirective(int column)
            for (int i = 0; i < sortingColumns.size(); i++)
                Directive directive = (Directive)sortingColumns.get(i);
                if (directive.column == column)
                    return directive;
            return EMPTY_DIRECTIVE;
        public int getSortingStatus(int column)
            return getDirective(column).direction;
        private void sortingStatusChanged()
            clearSortingState();
            fireTableDataChanged();
            if (tableHeader != null)
                tableHeader.repaint();
        public void setSortingStatus(int column, int status)
            Directive directive = getDirective(column);
            if (directive != EMPTY_DIRECTIVE)
                sortingColumns.remove(directive);
            if (status != NOT_SORTED)
                sortingColumns.add(new Directive(column, status));
            sortingStatusChanged();
        protected Icon getHeaderRendererIcon(int column, int size)
            Directive directive = getDirective(column);
            if (directive == EMPTY_DIRECTIVE)
                return null;
            return new Arrow(directive.direction == DESCENDING, size, sortingColumns.indexOf(directive));
        private void cancelSorting()
            sortingColumns.clear();
            sortingStatusChanged();
        public void setColumnComparator(Class type, Comparator comparator)
            if (comparator == null)
                columnComparators.remove(type);
            else
                columnComparators.put(type, comparator);
        protected Comparator getComparator(int column)
            Class columnType = tableModel.getColumnClass(column);
            Comparator comparator = (Comparator) columnComparators.get(columnType);
            if (comparator != null)
                return comparator;
            if (Comparable.class.isAssignableFrom(columnType))
                return COMPARABLE_COMAPRATOR;
            return LEXICAL_COMPARATOR;
        private Row[] getViewToModel()
            if (viewToModel == null)
                int tableModelRowCount = tableModel.getRowCount();
                viewToModel = new Row[tableModelRowCount];
                for (int row = 0; row < tableModelRowCount; row++)
                    viewToModel[row] = new Row(row);
                if (isSorting())
                    Arrays.sort(viewToModel);
            return viewToModel;
        public int modelIndex(int viewIndex)
                 return getViewToModel()[viewIndex].modelIndex;     
        private int[] getModelToView()
            if (modelToView == null)
                int n = getViewToModel().length;
                modelToView = new int[n];
                for (int i = 0; i < n; i++)
                    modelToView[modelIndex(i)] = i;
            return modelToView;
        // TableModel interface methods
        public int getRowCount()
            return (tableModel == null) ? 0 : tableModel.getRowCount();
        public int getColumnCount()
            return (tableModel == null) ? 0 : tableModel.getColumnCount();
        public String getColumnName(int column)
            return tableModel.getColumnName(column);
        public Class getColumnClass(int column)
            return tableModel.getColumnClass(column);
        public boolean isCellEditable(int row, int column)
            return tableModel.isCellEditable(modelIndex(row), column);
        public Object getValueAt(int row, int column)
            return tableModel.getValueAt(modelIndex(row), column);
        public void setValueAt(Object aValue, int row, int column)
            tableModel.setValueAt(aValue, modelIndex(row), column);
        // Helper classes
        private class Row implements Comparable
            private int modelIndex;
            public Row(int index)
                this.modelIndex = index;
            public int compareTo(Object o)
                int row1 = modelIndex;
                int row2 = ((Row) o).modelIndex;
                for (Iterator it = sortingColumns.iterator(); it.hasNext();)
                    Directive directive = (Directive) it.next();
                    int column = directive.column;
                    Object o1 = tableModel.getValueAt(row1, column);
                    Object o2 = tableModel.getValueAt(row2, column);
                    int comparison = 0;
                    // Define null less than everything, except null.
                    if (o1 == null && o2 == null)
                        comparison = 0;
                    } else if (o1 == null)
                        comparison = -1;
                    } else if (o2 == null)
                        comparison = 1;
                    } else {
                        comparison = getComparator(column).compare(o1, o2);
                    if (comparison != 0)
                        return directive.direction == DESCENDING ? -comparison : comparison;
                return 0;
        private class TableModelHandler implements TableModelListener
            public void tableChanged(TableModelEvent e)
                // If we're not sorting by anything, just pass the event along.            
                if (!isSorting())
                    clearSortingState();
                    fireTableChanged(e);
                    return;
                // If the table structure has changed, cancel the sorting; the            
                // sorting columns may have been either moved or deleted from            
                // the model.
                if (e.getFirstRow() == TableModelEvent.HEADER_ROW)
                    cancelSorting();
                    fireTableChanged(e);
                    return;
                // We can map a cell event through to the view without widening            
                // when the following conditions apply:
                // a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and,
                // b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and,
                // c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and,
                // d) a reverse lookup will not trigger a sort (modelToView != null)
                // Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS.
                // The last check, for (modelToView != null) is to see if modelToView
                // is already allocated. If we don't do this check; sorting can become
                // a performance bottleneck for applications where cells 
                // change rapidly in different parts of the table. If cells
                // change alternately in the sorting column and then outside of            
                // it this class can end up re-sorting on alternate cell updates -
                // which can be a performance problem for large tables. The last
                // clause avoids this problem.
                int column = e.getColumn();
                if (e.getFirstRow() == e.getLastRow()
                        && column != TableModelEvent.ALL_COLUMNS
                        && getSortingStatus(column) == NOT_SORTED
                        && modelToView != null)
                    int viewIndex = getModelToView()[e.getFirstRow()];
                    fireTableChanged(new TableModelEvent(TableSorter.this,
                                                         viewIndex, viewIndex,
                                                         column, e.getType()));
                    return;
                // Something has happened to the data that may have invalidated the row order.
                clearSortingState();
                fireTableDataChanged();
                return;
        private class MouseHandler extends MouseAdapter
            public void mouseClicked(MouseEvent e)
                JTableHeader h = (JTableHeader) e.getSource();
                TableColumnModel columnModel = h.getColumnModel();
                int viewColumn = columnModel.getColumnIndexAtX(e.getX());
                int column = columnModel.getColumn(viewColumn).getModelIndex();
                if (column != -1)
                    int status = getSortingStatus(column);
                    if (!e.isControlDown())
                        cancelSorting();
                    // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
                    // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
                    status = status + (e.isShiftDown() ? -1 : 1);
                    status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
                    setSortingStatus(column, status);
        private static class Arrow implements Icon
            private boolean descending;
            private int size;
            private int priority;
            public Arrow(boolean descending, int size, int priority)
                this.descending = descending;
                this.size = size;
                this.priority = priority;
            public void paintIcon(Component c, Graphics g, int x, int y)
                Color color = c == null ? Color.GRAY : c.getBackground();            
                // In a compound sort, make each succesive triangle 20%
                // smaller than the previous one.
                int dx = (int)(size/2*Math.pow(0.8, priority));
                int dy = descending ? dx : -dx;
                // Align icon (roughly) with font baseline.
                y = y + 5*size/6 + (descending ? -dy : 0);
                int shift = descending ? 1 : -1;
                g.translate(x, y);
                // Right diagonal.
                g.setColor(color.darker());
                g.drawLine(dx / 2, dy, 0, 0);
                g.drawLine(dx / 2, dy + shift, 0, shift);
                // Left diagonal.
                g.setColor(color.brighter());
                g.drawLine(dx / 2, dy, dx, 0);
                g.drawLine(dx / 2, dy + shift, dx, shift);
                // Horizontal line.
                if (descending) {
                    g.setColor(color.darker().darker());
                } else {
                    g.setColor(color.brighter().brighter());
                g.drawLine(dx, 0, 0, 0);
                g.setColor(color);
                g.translate(-x, -y);
            public int getIconWidth()
                return size;
            public int getIconHeight()
                return size;
        private class SortableHeaderRenderer implements TableCellRenderer
            private TableCellRenderer tableCellRenderer;
            public SortableHeaderRenderer(TableCellRenderer tableCellRenderer)
                this.tableCellRenderer = tableCellRenderer;
            public Component getTableCellRendererComponent(JTable table,
                                                           Object value,
                                                           boolean isSelected,
                                                           boolean hasFocus,
                                                           int row,
                                                           int column)
                Component c = tableCellRenderer.getTableCellRendererComponent(table,
                        value, isSelected, hasFocus, row, column);
                if (c instanceof JLabel) {
                    JLabel l = (JLabel) c;
                    l.setHorizontalTextPosition(JLabel.LEFT);
                    int modelColumn = table.convertColumnIndexToModel(column);
                    l.setIcon(getHeaderRendererIcon(modelColumn, l.getFont().getSize()));
                return c;
        private static class Directive
            private int column;
            private int direction;
            public Directive(int column, int direction)
                this.column = column;
                this.direction = direction;
    }any input will be appreciated.
    thanks
    Peter

    The code you posted doesn't help us at all. Its just a duplicate of the code from the tutorial. The custom code is what you have written. For example do you update the TableModel from the Event Thread? Do you update the SortModel or the DefaultTableModel? If you actually provide your test code and somebody has already downloaded the sort classes, then maybe they will test your code against the classes. But I doubt if people will download the sort classes and create a test program just to see if they can duplicate your results (at least I know I'm not about to).

  • How to use the TableSorter for two tables at the same view?

    Hello,
    I am using the TableSorter object in order to sort Dynpro tables.
    Suppose I have two tables at the same view, is it possible to use it seperatly for both of them?
    I assume that at the wdModifyView method I will need to catch the table that the user clicked on, yet I don't have an idea of how to do it...

    Hi Roy,
    Constructor of TableSorter
    public TableSorter(IWDTable table, IWDAction sortAction, Comparator[] comparators)
    So, you have to create instance of TableSorter class for each table on the view.
    best regards, Maksim Rashchynski.

  • How to use a custom comparator in a TableSorter?

    Hi,
    I want to use a custom comparator for sorting a table by a specific column.
    As you possibly know, the constructor for the TableSorter class looks like this:
    TableSorter(IWDTable table, IWDAction sortAction, Map comparators);
    As Map is an Interface I chose Hashmap as comparator container. So, I use the put(Key, Value) method to insert my own comparator into the Hashmap in order to deliver this Object to the TableSorter constructor.
    But there is an essential problem:
    I assume, that the column which is to be associated with my comparator is determined by the key of the Map object from the TableSorter constructor.
    Presuming this, <u>what should the map key be/look like?</u>
    An Integer counted from the columns? The column header as String? Whatever? Or am I on the wrong way?
    PS:
    Hours of search did not lead me to some kind of documentation or javadoc of the TableSorter class! This can't be, does someone have a link please?
    Thanks a lot for any help.

    (sorry Mrutyun, this did not help.)
    Ok, I solved it; let me share it with you:
    public class ExampleView
            public static void wdDoModifyView(IPrivateExampleView wdThis, IPrivateExampleView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
                     * A custom Comparator class is used for sorting by Severity.
                     * An Object of it is delivered to an object of a Map class to be delivered to the TableSorter constructor.
                     * The Map class consists of key-value pairs, and the TableSorter must accept the Key of it
                     * because he uses it to assign the mapped Comparator to the column of the table to be sorted!
                     * And this is done with the ID of the Element, which shall be sorted with the Comparator, used as Map Key.
                     * All other columns of the assigned tables will be sorted by default Comparators.
                    IWDTable table = (IWDTable) view.getElement("[TableName]");
                    HashMap tableComps = new HashMap();
                    tableComps.put(view.getElement("[ColumnName]").getId(), new MyComp(wdContext.currentExampleElement())); //The map key value I looked for is the ID of the Element of the Column!
                    wdContext.current/*yourContextNode*/Element().setTableSort(
                            new TableSorter(table, wdThis.wdGetSortTableRowAction(),
                                    tableComps)); //Insert HashMap with the new Comparator
            public void onActionSortTableRow(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
            //@@begin onActionSortTableRow(ServerEvent)
                            wdContext.currentConfigurationElement().getTableSort().sort(wdEvent, wdContext.nodeOpenIncident());
            //@@end
    As you see, the Column which is to be sorted by the custom Comparator "MyComp", is clearly assigned to it. Thus, is will only be used when sorting by this column is done.
    The "inActionSort" method is as usual.
    My Comparator sorts a column which contains variables of a "SimpleType" with an enumeration. (If you need help with this, feel free to write me.) To achieve this, the Comparator needs to know what this SimpleType consists of. That's why I deliver this Element per Constructor to it.
    public class MyComp implements Comparator
         MappedNodeElement element;
         public SeverityComp(I/*one*/Element element)
              this.element = element;
         public SeverityComp(I/*another*/Element element)
              this.element = element;
         public int compare(Object severity1, Object severity2)
    Because MappedNodeElement is such abstract, it can be used by several different Tables, provided they use the same SimpleType.
    Concerning my quest for this resolution, I hope this is helpful.
    null

  • How to get the TableSorter File in to project

    Hi
    I am developing Table Example application.
    i want to implement table sort on that table.
    to implement that we need TableSorter Java Class to achive this.
    so please let me know how to get that file in to my project.
    regards
    mmukesh

    From the above reply you can get the TableSorter.java file.
    Follow the below steps to achieve sorting the table:
    1. Create a folder in the src->packages folder say util
    2. Place the TableSorter.java in that folder.
    3. Create a Context variable in the view say 'sorter' and in its properties enter the type say com.test.util.TableSorter
    4. Get the table and assign the sorter context to it.
    IWDTable table = (IWDTable)view.getElement("<table name>");
    wdContext.currentContextElement().setSorter(new TableSorter(table,wdThis.wdGetSortAction(),null));
    5. Create a method sort and write the below code: (the node in the code refers to the table)
             wdContext.currentContextElement().getSorter().sort(wdEvent,wdContext.<node tablename>);
    Hope this helps.
    Regards,
    Amar.
    Message was edited by:
            Amar Bhagat Challa

  • How to use TableSorter class with DefaultTableModel

    Hi Friends
    Please tell me how to use TableSorter Class which is in the Java. Tutorials with DefaultTableModel.
    i saw in a thread there it was given that we have to pass the DefaultTableModel to the TableSorter Class.
    I tried to use like that. But i am getting Error Like Exception occurred during event dispatching:
    I am posting the part of Code where i use the DefaultTableModel
         private void displayavailablity(String selectedAuthor)
                   try
                        Vector columnNames = new Vector();
                        Vector data1 = new Vector();
                        String bname,bauthor,bcategory,bref1,bavail,bid;
                        int bref,mid,num;
                        rs = st.executeQuery("SELECT BId,BName,BAuthorName,BAuthorandPublisher,BCat FROM Books where BAuthorandPublisher='" +selectedAuthor+"'");     
                        ResultSetMetaData md= rs.getMetaData();
                        int columns =md.getColumnCount();
                        String booktblheading[]={"NUMBER","BOOK NAME","AUTHOR","CODE","CATEGORY"};
                        for(int i=1; i<= booktblheading.length;i++)
                             columnNames.addElement(booktblheading[i-1]);
                        while(rs.next())
                             Vector row = new Vector(columns);
                             for(int i=1;i<=columns;i++)
                                  row.addElement(rs.getObject(i));
                             data1.addElement(row);
                             //System.out.println("data is:"+data);
                        ((DefaultTableModel)table.getModel()).setDataVector(data1,columnNames);
                        TableSorter sorter = new TableSorter((DefaultTableModel)table.getModel());
                        rs.close();
                   catch(SQLException ex)
                        System.out.println("ERROR IS HERE");
                        ex.printStackTrace();
         }Please help me on this issue Otherwise Please give me some Sample coding to implement this sorting. with DefaultTableModel
    Thank you for your service
    Cheers
    Jofin

    I don't know about any TableSorter class, but I suppose you mean javax.swing.table.TableRowSorter.
    The TableRowSorter is to be attached to the JTable, not to the data model. Here's a cut'n'paste from the last time I used it:
    RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel);
    myTable.setRowSorter(sorter);
    And heres from the JDK1.6 documentation:
    TableModel myModel = createMyTableModel();
    JTable table = new JTable(myModel);
    table.setRowSorter(new TableRowSorter(myModel));
    Check out http://java.sun.com/javase/6/docs/api/javax/swing/table/TableRowSorter.html. I find it to be good documentation.

  • Problem While checkin in NWDI  adding TableSorter.java class in src of DC

    Hi
    I have added TableSorter.java class in Source folder of One Develop Component and implemented the code to sort the table.It is working fine Locally.
        While I am trying to checkin in NWDI it is throwing error messages like
    location: package tests
        private com.sap.tc.webdynpro.tests.utils.TableSorter _tableSorter;
                                              ^
    /usr/sap/GJ0/JC00/j2ee/cluster/server0/temp/CBS/149/.B/21713/t/47794B28F57C19FA453190A8074C0706/gwd/packages/com.sap.tc.webdynpro.tests.utils.TableSorter/TableBasketView.java :1851: cannot resolve symbol
    symbol  : class TableSorter
    location: package tests
        public com.sap.tc.webdynpro.tests.utils.TableSorter getTableSorter() {
                                             ^
    /usr/sap/GJ0/JC00/j2ee/cluster/server0/temp/CBS/149/.B/21713/t/47794B28F57C19FA453190A8074C0706/gwd/packages/com.sap.tc.webdynpro.tests.utils.TableSorter/TableBasketView.java :1859: cannot resolve symbol
    symbol  : class TableSorter
    location: package tests
        public void setTableSorter(com.sap.tc.webdynpro.tests.utils.TableSorter value) {
                                                                 ^
    /usr/sap/GJ0/JC00/j2ee/cluster/server0/temp/CBS/149/.B/21713/t/47794B28F57C19FA453190A8074C0706/gwd/packages/com.sap.tc.webdynpro.tests.utils.TableSorter/TableBasketView.java :1886: cannot resolve symbol
    symbol  : class TableSorter
    location: package tests
              this._tableSorter = (sap.tc.webdynpro.tests.utils.TableSorter)value;
                                                                 ^
    /usr/sap/GJ0/JC00/j2ee/cluster/server0/temp/CBS/149/.B/21713/t/47794B28F57C19FA453190A8074C0706/gwd/packages/sap.tc.webdynpro.tests.utils.TableSorter/TableBasketView.java:262: cannot resolve symbol
    symbol  : class TableSorter
    location: class sap.tc.webdynpro.tests.utils.TableSorter.TableBasketView.java
         wdContext.currentContextElement().setTableSorter((new TableSorter(table, wdThis.wdGetActSortPrice(), null)));
    Please help me.
    Thanks&Regards

    Hi,
    Where exactly did you put your TableSorter.java?
    It should be in src\packages\<your package foleders>\util
    Please also don't forget to add your TableSorter.java in the OpenActivity which you want to check in.
    I suggest there is also another way to do this but I didn't try it:
    Create new Java Project DC
    Put your TableSorter.java there
    Add all necessary DC for build
    Create two public parts (assembly and compilation)
    And use this parts in your WD DC
    Regards
    Pavel

  • How to make tablesorter work for GroupedColumns??

    Hi all,
    I imported the class of TableSorter.java to my project. It automatically picks up my normal columns, they all can be sorted.
    but the groupedColumns generated by the drag and drop table node into the design area wont pick up, even i set the property of "onAction" of the column to "Sort"(method) it wont sort the content for me.
    how to make it work?
    thanks

    hi!
    you can get lead selection in the action handler then inset your code for currentContextElement.
    wdContext.currentContextElement().getTableSorter().sort(wdEvent, wdContext.nodeXXX());
    thanks
    vishal

  • TableSorter in Numerical Order instead of Alphabatical Order

    I am using the TableSorter from java tutorial. I have a table that contains columns of Integer, Float and String. The TableSorter from Tutorial sorts all columns alphbatically.
    Could someone tell me how do I sort columns that contains Integer or Float? I like to have the numerical order not alphabatical order.
    Thank you very much!!

    You've got three threads going on this topic. Everyone is telling you that the TableSorter class from the Swing table tutorial will do what you want. So, do you get the impression that you are doing something wrong? You've given us no idea what you code looks like so how are we supposed to guess what you are doing?
    The more information you provide with the question, the better the chance for a successfull answer. So post your code and maybe people will take the time to look at it.
    This [url http://forum.java.sun.com/thread.jsp?forum=57&thread=419688]thread shows how easy it is to create a simple test program to demonstrate a problem/solution. Chances are while you creating this demo, you will find your mistake.

  • TableSorter over more than one columns like Excel

    Hi Experts,
    do you have a example for TableSorter over more than one columns like Excel?
    Thank you very much.
    regards
    Steffen

    Hey,
    Please download the application mentioned in it.
    When i have excuted the application i could find sort enabled for all the columns.
    wdContext.currentContextElement().getTableSorter().sort( wdEvent, wdContext.nodeTableSet() );
    Please check it..
    Jithin
    Edited by: jithin james on Apr 16, 2009 10:47 AM

  • JTable and TableSorter

    Greetings!
    I know this has been a topic before in this forum, but I can�t get TableSorter from the Java Tutorial properly working. What I am experiencing is following:
    I populate my JTable with data. Everything is displayed unordered. Now I can sort the data by clicking on a column header. Everything is working fine. BUT, if I now try to select a checkbox in a special row, the data will be displayed in it�s original, unsorted form again.
    Can someone explain to me how I can avoid this? I want the display to stay in it�s sorted form, although I�m selecting a checkbox. This should be possible, isn�t it?
    Regards and thanks for your help in advance, Michael.
    PS: I�ve tried the solution from Jason Goemaat, but unfurtunately it is not working for me...

    You need a method to convert the sorted row (map) index into the underlying model row index. Something like this in the SortMap maybe?public int convertMapIndexToModel( int mapRow ) {
        if( mapRow < 0 )
            return mapRow;
        if( mapRow+1 > indexes.length )
            return -1;
        int rowi = indexes[ mapRow ];
        return rowi;

  • TableSorter with WD in NW7.1

    Hello Community,
    i'am testing with the table ui-component. now i want to realize sorting. for that i found here that one should use TableSorter.java as an utility-class for sorting.
    doing so far works fine, but i have some additionals problems and maybee one of you could help me.
    what is done so far:
    with
      IWDTable table = (IWDTable) view.getElement("Table");
      wdContext.currentContextElement().setTableSorter(new TableSorter(table, wdThis.wdGetSortAction(),
                          null));     
      in the wdDoModifyView Method of my view controller i instantiate my TableSorter and bind it to a context-attribute.
    and with:
    wdContext.currentContextElement().getTableSorter().sort(wdEvent, wdContext.nodeReturn());
    in my OnSort-Action  sorting takes place.
    The problems:
    1.)
    doing above with the mentioned TableSorter-Class my table in unsorted at the beginning. the user has to click on a header to sort the data on that colum.
    What i need is an initial sort, also showing the sort-icons correctly in the header
    2.)
    i have a detail view for the current-context-node. this is implemented by an additional view controller, which i connected via plugs and appropriate actions. When i return from a detail-view view-controller to the table-view-controller via plugOut, plugIn the data then is not correctly sorted.
    Does anybody know how to achive this?
    regards
    Matthias

    Hello,
    the method sortTable is not known in my TableSorter-Class, which is i discovered for nw04s in sdn. theres only one sort-method which expects an Event as addtional-parameter (as you can see in step 2 in my question).
    my idea as a workaround was to call the sort-method after inistantiating the TableSorter-Class in wdModifyView. but i didn't know to create an event with the neccessary parameters for the event. but looking into the TableSort-Class and the Method sort i discovered that the method extracts the columnname and sortdirection as strings out of the event. so i created a copy of the Sort-Method in the TableSorter-Class with the same name but the parameters columname and sortdirection as string. Then it does the same then the original sort-method.
    This works fine so far when calling this new method in wdModifyView after instantiating the TableSorter-Class. But unfortunatly, it does not show the sort-icons in the column header
    Do you have any ideas how to show the icons from the first rendering of the view?
    regards
    Matthias

  • Implementation of TableSorter class partially successful

    Greetings, esteemed experts.
    I have successfully applied the TableSorter class to my table, and sorting occurs correctly in runtime. The sort is performed in ascending order, which matches the clients' requirement. However, the tooltip text for the sort icon (up/down arrows) remains as 'not sorted', and clicking the icon multiple times does not result in the sort toggling between ascending and descending directions.
    All the articles and posts I have read regarding the TableSorter class seem to indicate that this is not consistent with its design.
    Any wisdom to share?

    Sorting was not being invoked properly because the field that is being sorted is a time field. The string comparison collator class could not sort the values, so the TableSorter.class Comparator method was modified to parse out hour and minute values. Fortunately, for our application, no other columns in the table have the 'sortable' requirement, so we could customize the class file for the project without impacting any other functionality.

  • JTable (yes, again) with TableSorter - exception in the second request.

    While using the TableSorter the data is populated correctly and I manage to sort the items (beautiful)
    say I ask for a list of items and the return result is 20 and the second time I'll ask for a list of items where the return result is greater than 20 items an error will occur with reference to: java.lang.ArrayIndexOutOfBoundsException : 10
    com.softme.jtable.Renderer.TableSorter.modelIndex(TableSorter.java:207)
    com.softme.jtable.Renderer.TableSorter.getValueAt(TableSorter.java:249)
        public int modelIndex(int viewIndex)
             return getViewToModel()[viewIndex].modelIndex;         
        }any idea why this happens?

    I am also getting this same Exception... I have tried various things to prevent this from happening. I can state that in my case I am running table model updates in a SwingWorker Thread to create a visual effect on the screen (rows are being processed and updated as the user watches)
    Could this be a problem of the JTable object accessing the getValue method to update the screen at the same time as the Thread is accessing it for the test value locking the model index object?
    Just a thought.
    This problem is very annoying to the user as it only happens once-in-a-while. Thanks for any help on this problem.
    Here is the changes I made to the code and the error I get... As you can see I test for NULL before running the line, it passes and then STILL gives a NullPointerExcpetion... this is why I am thinking Thread issue...
    public int modelIndex(int viewIndex) {
             Row[] row = getViewToModel();
             if (row == null) System.out.println("?: " +viewIndex);
             if (row != null) {
                  return row[viewIndex].getModelIndex(); //this line is throwing the NPE
             else
                  return -1;
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
         at com.adriansteel.rpg.rpgSubfileSorter.modelIndex(rpgSubfileSorter.java:323)
         at com.adriansteel.rpg.rpgSubfileSorter.getValueAt(rpgSubfileSorter.java:363)
         at javax.swing.JTable.getValueAt(Unknown Source)
         at javax.swing.JTable.prepareRenderer(Unknown Source)
         at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
         at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
         at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
         at javax.swing.plaf.ComponentUI.update(Unknown Source)
         at javax.swing.JComponent.paintComponent(Unknown Source)
         at javax.swing.JComponent.paint(Unknown Source)
         at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
         at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
         at javax.swing.JComponent._paintImmediately(Unknown Source)
         at javax.swing.JComponent.paintImmediately(Unknown Source)
         at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
         at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
         at java.awt.event.InvocationEvent.dispatch(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)

  • TableSorter class never ever calls getModelToView()

    I am using TableSorter class to sort tables. There is a piece of optimization code that never gets called: getModelToView(). For that method to be called a check is performed (modelToView != null). But modelToView is assigned inside that method! This causes a single cell update to trigger fireTableDataChanged(). Is that a known bug? Is there a fix?

    I see what you mean.. you're right, it seems like modelToView will always be null.
    I found another bug.. when mouse is clicked on the tableheader area where it doesn't have any column (when table is stretched it can have no column there) , columnModel.getColumnIndexAtX(e.getX()) returns -1, and if the check there is not added, then get a runtime out-of-bounds exception on the following line columnModel.getColumn(viewColumn).getModelIndex() because viewColumn is set to -1. See the code snippet below:
    public void mouseClicked(MouseEvent e) {
                JTableHeader h = (JTableHeader) e.getSource();
                TableColumnModel columnModel = h.getColumnModel();
                int viewColumn = columnModel.getColumnIndexAtX(e.getX());
                if(viewColumn == -1) {  // added!
                    return;
                int column = columnModel.getColumn(viewColumn).getModelIndex();

Maybe you are looking for