List of usage examples for javax.swing JTable getDefaultRenderer
public TableCellRenderer getDefaultRenderer(Class<?> columnClass)
TableColumn
. From source file:org.yccheok.jstock.gui.JTableUtilities.java
public static void insertTableColumnFromModel(JTable jTable, Object value, int clickedColumnIndex) { boolean isVisible = true; try {/* w w w . ja v a2 s . c om*/ TableColumn tableColumn = jTable.getColumn(value); } catch (java.lang.IllegalArgumentException exp) { isVisible = false; } if (isVisible) return; TableModel tableModel = jTable.getModel(); final int modelIndex = getModelColumnIndex(jTable, value); Class c = tableModel.getColumnClass(modelIndex); TableColumn tableColumn = new javax.swing.table.TableColumn(modelIndex, 0, jTable.getDefaultRenderer(c), jTable.getDefaultEditor(c)); jTable.addColumn(tableColumn); makeTableColumnWidthFit(jTable, jTable.getColumnCount() - 1, 5); // If we right clicked on the 3rd column, and select a new column, we // would like the new column to be inserted into 4th column. Note that, // clickedColumnIndex will be < 0, if we right clicked on empty area. if (clickedColumnIndex < 0) { // Have it in the last column when we right clicked on empty area. jTable.moveColumn(jTable.getColumnCount() - 1, jTable.getColumnCount() - 1); } else { // +1, as we want our newly inserted column to be at the right of // clicked column. jTable.moveColumn(jTable.getColumnCount() - 1, Math.min(jTable.getColumnCount() - 1, clickedColumnIndex + 1)); } }