[Schmitzm-commits] r2150 - trunk/schmitzm-core/src/main/java/de/schmitzm/swing

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Wed Nov 28 18:36:29 CET 2012


Author: mojays
Date: 2012-11-28 18:36:29 +0100 (Wed, 28 Nov 2012)
New Revision: 2150

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
Log:
SwingUtil: bugfix in .getRendererdTableCellValue(.)

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java	2012-11-28 16:55:35 UTC (rev 2149)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java	2012-11-28 17:36:29 UTC (rev 2150)
@@ -2661,16 +2661,27 @@
      * @param table a table
      * @param row row index
      * @param col column index
+     * @param modelCoord indicates whether row and column are specified as model index (TRUE)
+     *                   or view index (FALSE); view index should be used if coordinates come from
+     *                   selection model! 
      * @return {@code JTable.getValueAt(int, int).toString()} if no {@link DefaultTableCellRenderer}
      *         is used for cell
      */
-    public static String getRendererdTableCellValue(JTable table, int row, int col) {
-      TableCellRenderer rend = table.getCellRenderer(row, col);
-      if ( rend instanceof HighlightCellRenderer )
-        rend = ((HighlightCellRenderer)rend).getPipedRenderer();
-      if ( rend instanceof DefaultTableCellRenderer )
-        return ((DefaultTableCellRenderer)rend).getText();
-      Object cellValue = table.getValueAt(row, col);
+    public static String getRendererdTableCellValue(JTable table, int row, int col, boolean modelCoord) {
+//      int modelRow = modelCoord ? row : table.convertRowIndexToModel(row);
+//      int modelCol = modelCoord ? col : table.convertColumnIndexToModel(col);
+      int viewRow  = modelCoord ? table.convertRowIndexToView(row) : row;
+      int viewCol  = modelCoord ? table.convertColumnIndexToView(col) : col;
+      
+      // Determine cell value
+      Object cellValue = table.getValueAt(viewRow, viewCol);
+      // Render value as in table view
+      TableCellRenderer rend = table.getCellRenderer(viewRow, viewCol);
+      Component rendComp = rend.getTableCellRendererComponent(table, cellValue, false, false, viewRow, viewRow);
+      // if possible, use the rendered text 
+      if ( rendComp instanceof DefaultTableCellRenderer )
+        return ((DefaultTableCellRenderer)rendComp).getText();
+      
       return cellValue != null ? cellValue.toString() : null; 
     }
 



More information about the Schmitzm-commits mailing list