List of utility methods to do JTable Cell
void | addComboCell(TableColumn column, Object[] items) add Combo Cell column.setCellEditor(new DefaultCellEditor(new JComboBox(items))); |
void | copyCells(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); ... |
Dimension | defaultTableCellSize() 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(); |
Rectangle | getCellBounds(JTable table, int top, int bottom) get Cell Bounds return table.getCellRect(top, 0, true).union(table.getCellRect(bottom, 0, true));
|
Rectangle | getCellRectangle(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; |
String | getColumnNames(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; |
String | getContent(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); ... |
String | getCurrentSelectionContent(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); |
int | getIntercellWidth(JTable table) get Intercell Width return (int) table.getIntercellSpacing().getWidth(); |
Color | getTableFocusCellForeground() get Table Focus Cell Foreground return UIManager.getColor("Table.focusCellForeground"); |