List of utility methods to do JTable Cell
int | getWidestCellInColumn(JTable table, TableColumn col) get Widest Cell In Column int column = col.getModelIndex(); int max = 0; for (int row = 0; row < table.getRowCount(); ++row) { TableCellRenderer renderer = table.getCellRenderer(row, column); Component comp = renderer.getTableCellRendererComponent(table, table.getValueAt(row, column), false, false, row, column); max = Math.max(comp.getPreferredSize().width, max); return max; |
int | getWidestCellInColumn(TableColumn col, JTable table) Figures out the width of the widest cell in a TableColumn Lifted from Graphic Java's chapter on Tables. String methodName = MODULE_NAME + "getWidestCellInColumn(TableColumn, JTable)"; int retval = -1; int modelIndex = col.getModelIndex(); int width = 0; int maxWidth = 0; for (int i = 0; i < table.getRowCount(); i++) { TableCellRenderer renderer = table.getCellRenderer(i, modelIndex); Component comp = renderer.getTableCellRendererComponent(table, table.getValueAt(i, modelIndex), false, ... |
boolean | isCellVisible(JTable table, int rowIndex, int vColIndex) is Cell Visible if (!(table.getParent() instanceof JViewport)) { return false; JViewport viewport = (JViewport) table.getParent(); Rectangle rect = table.getCellRect(rowIndex, vColIndex, true); Point pt = viewport.getViewPosition(); rect.setLocation(rect.x - pt.x, rect.y - pt.y); return new Rectangle(viewport.getExtentSize()).contains(rect); ... |
void | renderHTMLCell(final StringBuffer buffer, final String contents, final String css, final int align) Render a single table cell in HTML with an optional style. String strAlign; strAlign = ALIGN_LEFT; if (align == SwingConstants.LEFT) { strAlign = ALIGN_LEFT; } else if (align == SwingConstants.RIGHT) { strAlign = ALIGN_RIGHT; } else if (align == SwingConstants.CENTER) { strAlign = ALIGN_CENTER; ... |
void | setCellTextAllignment(JTable table, int alignment) set Cell Text Allignment DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer(); rightRenderer.setHorizontalAlignment(alignment); TableModel tableModel = table.getModel(); for (int columnIndex = 0; columnIndex < tableModel.getColumnCount(); columnIndex++) { table.getColumnModel().getColumn(columnIndex).setCellRenderer(rightRenderer); |
void | showCell(JTable table, int row, int column) Show cell. Rectangle rect = table.getCellRect(row, column, true); table.scrollRectToVisible(rect); table.clearSelection(); table.setRowSelectionInterval(row, row); |
void | showCell(JTable table, int row, int column) show Cell if (row >= table.getRowCount())
row = table.getRowCount() - 1;
Rectangle rect = table.getCellRect(row, column, true);
table.scrollRectToVisible(rect);
table.clearSelection();
table.setRowSelectionInterval(row, row);
|
void | startEditingAtCell(JTable table, int row, int column) start Editing At Cell table.editCellAt(row, column); table.getEditorComponent().requestFocusInWindow(); |