Example #1
0
 /** Select an Ujo */
 public int selectRow(Ujo row) {
   UjoTableModel model = getModel();
   if (row != null)
     for (int i = 0; i < model.getRowCount(); i++) {
       if (row == model.getRow(i)) {
         selectRow(i);
         return i;
       }
     }
   clearSelection();
   return -1;
 }
Example #2
0
  /** Returns a model in an array String format. */
  public List<List<String>> getStringModelArray(boolean header) {
    List<List<String>> result = new ArrayList<List<String>>(getRowCount());
    List<String> arrayRow;

    UjoTableModel model = getModel();

    // If Header
    if (header && getTableHeader() != null) {
      arrayRow = new ArrayList<String>();
      result.add(arrayRow);
      for (int col = 0; col < model.getColumnCount(); col++) {
        Key column = getColumn(col);
        TableCellRenderer renderer = getTableColumn(column).getHeaderRenderer();
        String cell = model.getColumnName(column);
        if (renderer != null) {
          Component comp =
              renderer.getTableCellRendererComponent(this, cell, false, false, -1, col);
          if (comp instanceof JLabel) {
            cell = ((JLabel) comp).getText();
          }
        }
        arrayRow.add(cell);
      }
    }

    for (int row = 0; row < model.getRowCount(); row++) {
      arrayRow = new ArrayList<String>();
      result.add(arrayRow);
      for (int col = 0; col < model.getColumnCount(); col++) {
        Key column = getColumn(col);
        TableCellRenderer renderer = getTableColumn(column).getCellRenderer();
        Object value = model.getValueAt(row, column);
        String cell = String.valueOf(value);
        if (renderer != null) {
          Component comp =
              renderer.getTableCellRendererComponent(this, value, false, false, row, col);
          if (comp instanceof JLabel) {
            cell = ((JLabel) comp).getText();
          }
        }
        arrayRow.add(cell);
      }
    }
    return result;
  }