Refine search
public int getHeaderHeight() { int height = 0; TableColumnModel columnModel = header.getColumnModel(); for (int column = 0; column < columnModel.getColumnCount(); column++) { TableColumn aColumn = columnModel.getColumn(column); TableCellRenderer renderer = aColumn.getHeaderRenderer(); if (renderer == null) {
historyTable.addMouseListener(new HistoryMenuMouseListener()); historyTable.setAutoCreateRowSorter(true); for (int i = 0; i < historyTable.getColumnModel().getColumnCount(); i++) { int width = 130; // Default switch (i) { break; historyTable.getColumnModel().getColumn(i).setPreferredWidth(width);
/** * Adjust the widths of all the columns in the table */ public void adjustColumns() { TableColumnModel tcm = this.tableAdjust.getColumnModel(); for (int i = 0 ; i < tcm.getColumnCount() ; i++) { this.adjustColumn(i); } }
tcm = table.getColumnModel(); hiddenColumns = new HashMap(); TableColumn column = tcm.getColumn(index); hiddenColumns.put(columnName, column); hiddenColumns.put(":" + columnName, new Integer(index)); int lastColumn = tcm.getColumnCount() - 1; if (column < lastColumn) { tcm.moveColumn(lastColumn, column);
Cursor cursor = header.getCursor(); if (columnIndex == tcm.getColumnCount() - 1 && cursor == Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR)) column = tcm.getColumn( columnIndex ); columnWidth = column.getWidth(); pressedX = e.getX();
public void paint(Graphics g, JComponent c) { Rectangle clipBounds = g.getClipBounds(); if (header.getColumnModel().getColumnCount() == 0) { return; TableColumn aColumn = header.getColumnModel().getColumn(columnIndex); TableCellRenderer renderer = aColumn.getHeaderRenderer(); if (renderer == null) { int headerHeight = 0; TableColumnModel columnModel = header.getColumnModel(); for (int column = 0; column < columnModel.getColumnCount(); column++) { TableColumn aColumn = columnModel.getColumn(column); TableCellRenderer renderer = aColumn.getHeaderRenderer(); if (renderer == null) { width += columnModel.getColumnMargin() * columnModel.getColumnCount(); if (width > Integer.MAX_VALUE) { width = Integer.MAX_VALUE;
public static void saveColumnWidthAndOrderToPrefs(JTable table, String widthPrefKey, String orderPrefKey) { StringBuilder columnWidthSettings = new StringBuilder(); StringBuilder columnOrderSettings = new StringBuilder(); boolean firstValue = true; for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) { TableColumn column = table.getColumnModel().getColumn(table.convertColumnIndexToView(i)); if (!firstValue) { columnWidthSettings.append(','); columnOrderSettings.append(','); } else { firstValue = false; } columnWidthSettings.append(column.getWidth()); columnOrderSettings.append(table.convertColumnIndexToModel(i)); } PreferencesDialog.saveValue(widthPrefKey, columnWidthSettings.toString()); PreferencesDialog.saveValue(orderPrefKey, columnOrderSettings.toString()); }
/** * Helper function to set preferred widths as a percentage. * http://stackoverflow.com/questions/1046005/jtable-column-resize-isnt-working */ private void setPreferredColumnWidths(double[] percentages) { Dimension tableDim = getPreferredSize(); double total = 0; for (int i = 0; i < getColumnModel().getColumnCount(); i++) { total += percentages[i]; } for (int i = 0; i < getColumnModel().getColumnCount(); i++) { TableColumn column = getColumnModel().getColumn(i); column.setPreferredWidth( (int)(tableDim.width * (percentages[i] / total))); } }
/** * Restore the widths of the columns in the table to its previous width */ public void restoreColumns() { TableColumnModel tcm = this.tableAdjust.getColumnModel(); for (int i = 0 ; i < tcm.getColumnCount() ; i++) { this.restoreColumn(i); } }
this.tcm = table.getColumnModel(); TableColumn column = tcm.getColumn(index); IndexedColumn ic = new IndexedColumn(index, column); if (hidden.put(columnName, ic) != null) { if (ic != null) { tcm.addColumn(ic.column); int lastColumn = tcm.getColumnCount() - 1; if (ic.index < lastColumn) { tcm.moveColumn(lastColumn, ic.index);
TableColumnModel tcm = getColumnModel(); for (int i = 0; i < tcm.getColumnCount(); i++) TableColumn tc = tcm.getColumn(i); tc.setPreferredWidth( tc.getWidth() );
public int getHeaderHeight() { int height = 0; TableColumnModel columnModel = header.getColumnModel(); for (int column = 0; column < columnModel.getColumnCount(); column++) { TableColumn aColumn = columnModel.getColumn(column); TableCellRenderer renderer = aColumn.getHeaderRenderer(); if (renderer == null) {
/** * Returns the number of accessible children in the object. If all of * the children of this object implement Accessible, than this method * should return the number of children of this object. * * @return the number of accessible children in the object. */ public int getAccessibleChildrenCount() { return JSyTableFooter.this.table.getColumnModel().getColumnCount(); }
public static void setColumnWidthAndOrder(JTable table, int[] defaultColumnsWidth, String widthPrefKey, String orderPrefKey) { table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // set the column width from saved value or defaults int[] widths = getIntArrayFromString(PreferencesDialog.getCachedValue(widthPrefKey, null)); int i = 0; for (int width : defaultColumnsWidth) { if (widths != null && widths.length > i) { width = widths[i]; } if (table.getColumnModel().getColumnCount() >= i) { TableColumn column = table.getColumnModel().getColumn(i++); column.setWidth(width); column.setPreferredWidth(width); } else { break; } } // set the column order int[] order = getIntArrayFromString(PreferencesDialog.getCachedValue(orderPrefKey, null)); if (order != null && order.length == table.getColumnCount()) { for (int j = 0; j < table.getColumnCount(); j++) { table.moveColumn(table.convertColumnIndexToView(order[j]), j); } } }
private int getTableColumnIndex(TableColumnModel aColumnModel, TableColumn aTableColumn) { for (int i = 0; i < aColumnModel.getColumnCount(); i++) { if (aColumnModel.getColumn(i) == aTableColumn) { return i; } } return -1; }
public void restoreColumns() { TableColumnModel tcm = table.getColumnModel(); for (int i = 0; i < tcm.getColumnCount(); i++) { restoreColumn(i); } }
{"eeeeeee", "aaaaaa", "bbbbbb", "cccccc", "dddddd",}}; private JTable table = new JTable(new DefaultTableModel(data, columnNames)); private TableColumnModel tcm = table.getColumnModel(); private Stack<TableColumn> colDeleted = new Stack<TableColumn>(); private JButton restoreButton = new JButton("Restore Column Size"); table.setFont(new Font("SansSerif", Font.BOLD + Font.PLAIN, 20)); JScrollPane scrollPane = new JScrollPane(table); for (int i = 0; i < (tcm.getColumnCount()); i++) { tcm.getColumn(i).setPreferredWidth(100); tcm.getColumn(2).setPreferredWidth(100); tcm.getColumn(2).setPreferredWidth(000); TableColumn colToDelete = table.getColumnModel().getColumn(table.getColumnCount() - 1); table.removeColumn(colToDelete); table.validate();
public ModelColumn[] getColumns() { ModelColumn[] res = new ModelColumn[columnModel.getColumnCount()]; for (int i = 0; i < res.length; i++) { res[i] = (ModelColumn) columnModel.getColumn(i); } return res; }
public void adjustColumns() { TableColumnModel tcm = table.getColumnModel(); for (int i = 0; i < tcm.getColumnCount(); i++) { adjustColumn(i); } }
{"eeeeeee", "aaaaaa", "bbbbbb", "cccccc", "dddddd",}}; private JTable table = new JTable(new DefaultTableModel(data, columnNames)); private TableColumnModel tcm = table.getColumnModel(); private Stack<TableColumn> colDeleted = new Stack<TableColumn>(); private JButton restoreButton = new JButton("Restore Column Size"); table.setFont(new Font("SansSerif", Font.BOLD + Font.PLAIN, 20)); JScrollPane scrollPane = new JScrollPane(table); for (int i = 0; i < (tcm.getColumnCount()); i++) { tcm.getColumn(i).setPreferredWidth(150); tcm.getColumn(2).setPreferredWidth(100); tcm.getColumn(2).setPreferredWidth(000); public void actionPerformed(ActionEvent e) { if (table.getColumnCount() > 0) { TableColumn colToDelete = table.getColumnModel().getColumn(table.getColumnCount() - 1); table.removeColumn(colToDelete); table.validate();