String () { int[] rows = comp.getSelectedRows(); int[] cols = comp.getColumnSelectionAllowed() ? comp.getSelectedColumns() : IntStream.range(0, comp.getColumnCount()).toArray(); StringBuilder sb = new StringBuilder(); int lastCol = cols.length == 0 ? -1 : cols[cols.length - 1]; for (int row : rows) { for (int col : cols) { Object value = comp.getModel().getValueAt(comp.convertRowIndexToModel(row), comp.convertColumnIndexToModel(col)); TableCellRenderer renderer = comp.getCellRenderer(row, col); append(sb, value, renderer.getTableCellRendererComponent(comp, value, false, false, row, col)); if (col != lastCol) sb.append(" "); } sb.append("\n"); } return sb.toString(); }