Java Utililty Methods JTable Cell

List of utility methods to do JTable Cell

Description

The list of methods to do JTable Cell are organized into topic(s).

Method

voidaddComboCell(TableColumn column, Object[] items)
add Combo Cell
column.setCellEditor(new DefaultCellEditor(new JComboBox(items)));
voidcopyCells(JTable table)
copy Cells
StringBuffer sb = new StringBuffer();
int row = table.getSelectedRow();
for (int col : table.getSelectedColumns()) {
    sb.append(table.getValueAt(row, col));
    sb.append("\t");
final StringSelection stsel = new StringSelection(sb.toString());
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stsel, stsel);
...
DimensiondefaultTableCellSize()
JTable cell size, based on global defaults.
JLabel label = new JLabel("miniminiminiminiminiminiminiminiminimini");
UIDefaults defaults = UIManager.getDefaults();
Object font = defaults.get("Table.font");
if (font instanceof Font)
    label.setFont((Font) font);
return label.getPreferredSize();
RectanglegetCellBounds(JTable table, int top, int bottom)
get Cell Bounds
return table.getCellRect(top, 0, true).union(table.getCellRect(bottom, 0, true));
RectanglegetCellRectangle(JTable table, int row, int column)
get Cell Rectangle
Rectangle rectangle = table.getCellRect(row, column, true);
rectangle.setLocation((int) (rectangle.getX() + table.getLocationOnScreen().getX()),
        (int) (rectangle.getY() + table.getLocationOnScreen().getY()));
return rectangle;
StringgetColumnNames(JTable table, String lineBreak, String cellBreak)
get Column Names
StringBuilder headerColumnsSB = new StringBuilder();
for (int i = 0; i < table.getTableHeader().getColumnModel().getColumnCount(); i++) {
    Object headerColumn = table.getColumnName(i);
    headerColumnsSB.append(headerColumn == null ? "" : headerColumn.toString());
    if (i != table.getTableHeader().getColumnModel().getColumnCount() - 1) {
        headerColumnsSB.append(cellBreak);
String headerColumns = headerColumnsSB.toString() + lineBreak;
return headerColumns;
StringgetContent(JTable table, String lineBreak, String cellBreak, int columnCount, int rowCount, int[] selectedRowsCount, int[] selectedColumsCount)
get Content
if (columnCount > 0 && rowCount > 0) {
    StringBuffer value = new StringBuffer();
    for (int i = 0; i < rowCount; i++) {
        for (int j = 0; j < columnCount; j++) {
            value.append(escapeContentBreaks(table.getValueAt(selectedRowsCount[i], selectedColumsCount[j]),
                    lineBreak, cellBreak));
            if (j < columnCount - 1) {
                value.append(cellBreak);
...
StringgetCurrentSelectionContent(JTable table, String lineBreak, String cellBreak)
Gets the content of current JTable selection as String or returns null, if the selection is invalid.
int numCols = table.getSelectedColumnCount();
int numRows = table.getSelectedRowCount();
int[] rowsSelected = table.getSelectedRows();
int[] colsSelected = table.getSelectedColumns();
return getContent(table, lineBreak, cellBreak, numCols, numRows, rowsSelected, colsSelected);
intgetIntercellWidth(JTable table)
get Intercell Width
return (int) table.getIntercellSpacing().getWidth();
ColorgetTableFocusCellForeground()
get Table Focus Cell Foreground
return UIManager.getColor("Table.focusCellForeground");