List of utility methods to do JTable Cell Renderer
void | adaptToTable(final JComponent renderer, final JTable table, boolean isSelected, final boolean hasFocus, final int row, final int column) Adapts the given component to the specified table instance, making it look just as a DefaultTableCellRenderer would. Color fg = null; Color bg = null; JTable.DropLocation dropLocation = table.getDropLocation(); if (dropLocation != null && !dropLocation.isInsertRow() && !dropLocation.isInsertColumn() && dropLocation.getRow() == row && dropLocation.getColumn() == column) { fg = UIManager.getColor("Table.dropCellForeground"); bg = UIManager.getColor("Table.dropCellBackground"); isSelected = true; ... |
void | applyRenderers(final JTable table, final TableCellRenderer[] renderers) apply Renderers final TableColumnModel columnModel = table.getColumnModel(); for (int i = 0; i < renderers.length; i++) { final TableCellRenderer rend = renderers[i]; if (rend != null) { columnModel.getColumn(i).setCellRenderer(rend); |
void | applyRenderers(final JTable table, final TableCellRenderer[] renderers) apply Renderers final TableColumnModel columnModel = table.getColumnModel(); for (int i = 0; i < renderers.length; i++) { final TableCellRenderer rend = renderers[i]; if (rend != null) { columnModel.getColumn(i).setCellRenderer(rend); |
void | configureColumn(JTable table, int columnNumber, Integer width, TableCellRenderer renderer, TableCellEditor editor) configure Column TableColumn column = table.getColumnModel().getColumn(columnNumber); if (width != null) column.setMaxWidth(width); if (renderer != null) column.setCellRenderer(renderer); if (editor != null) column.setCellEditor(editor); |
DefaultTableCellRenderer | createDefaultTableCellRenderer() create Default Table Cell Renderer DefaultTableCellRenderer label = new DefaultTableCellRenderer() { private static final long serialVersionUID = 1L; public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (table != null) { JTableHeader header = table.getTableHeader(); if (header != null) { setForeground(header.getForeground()); ... |
DefaultTableCellRenderer | getCellRenderer(final int hMargin) get Cell Renderer return new DefaultTableCellRenderer() { Border padding = BorderFactory.createEmptyBorder(0, hMargin, 0, hMargin); @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); setBorder(BorderFactory.createCompoundBorder(getBorder(), padding)); setHorizontalAlignment(JLabel.RIGHT); ... |
TableCellRenderer | getDefaultRenderer(JTable table, TableColumn column) Return the default cell renderer for the given JTable column. try { return table.getTableHeader().getDefaultRenderer(); } catch (Exception e) { throw new RuntimeException(e); |
Class extends TableCellRenderer> | getTableCellRendererClass(Class propType) get Table Cell Renderer Class return cellRendererClasses.get(propType);
|
void | setCellRender(JTable table, int columnIdx, TableCellRenderer render) set Cell Render TableColumn o = table.getColumnModel().getColumn(columnIdx); o.setCellRenderer(render); |
void | setTableRenderer(JTable table, Integer alignment) This method changes the default renderer of a given table final Integer alnt = alignment; table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() { private static final long serialVersionUID = -8183629931912150659L; public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (row % 2 != 0) { setBackground(Color.decode("#F0F0F0")); ... |