List of utility methods to do JTable Column Size Calculate
int | calculateColumnWidth_1(JTable table, int pos) calculate Column Widt_ for (int ii = 0; ii < table.getColumnModel().getColumnCount(); ii++) { TableColumn col = table.getColumnModel().getColumn(ii); if (ii == pos) { return col.getHeaderValue().toString().getBytes().length * 10; throw new RuntimeException("error!!"); |
void | fixedColumSize(TableColumn c, int width) fixed Colum Size c.setMinWidth(width); c.setMaxWidth(width); |
void | fixSize(TableColumn column, JTable table) Fix the size of a column according to the header text. TableCellRenderer rndr; rndr = column.getHeaderRenderer(); if (rndr == null) { rndr = table.getTableHeader().getDefaultRenderer(); Component c = rndr.getTableCellRendererComponent(table, column.getHeaderValue(), false, false, -1, column.getModelIndex()); int width = c.getPreferredSize().width + 10; ... |
void | initColumnSizes(JTable table) init Column Sizes TableModel model = (TableModel) table.getModel(); Object[] longValues = new Object[model.getColumnCount()]; for (int i = 0; i < model.getColumnCount(); i++) { longValues[i] = table.getModel().getColumnName(i); TableColumn column = null; Component comp = null; int headerWidth = 0; ... |
int | initColumnSizes(JTable table, boolean[] show) init Column Sizes TableColumn column = null; Component comp = null; int cellWidth = 0; TableModel model = table.getModel(); int numCols = model.getColumnCount(); int numRows = model.getRowCount(); if (show != null && show.length != numCols) show = null; ... |
void | initColumnSizes(JTable table, int rowStart, int rowEnd) Sets the width of the table columns to fit in the table data. boolean containsData = table.getRowCount() > 0; Component cellRendererComponent; int headerWidth; int cellWidth; TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); for (int columnIndex = 0; columnIndex < table.getColumnCount(); columnIndex++) { TableColumn column = table.getColumnModel().getColumn(columnIndex); cellRendererComponent = headerRenderer.getTableCellRendererComponent(table, column.getHeaderValue(), ... |
void | initializeTableColumns(JTable table, int size[]) initialize Table Columns TableCellRenderer dcr = table.getDefaultRenderer(Integer.class); if (dcr instanceof JLabel) { ((JLabel) dcr).setHorizontalAlignment(SwingConstants.CENTER); table.setDefaultRenderer(Integer.class, dcr); JTableHeader header = table.getTableHeader(); if (header != null) { TableCellRenderer headerRenderer = header.getDefaultRenderer(); ... |
boolean | pointOutsidePrefSize(JTable table, int row, int column, Point p) point Outside Pref Size if ((table.convertColumnIndexToModel(column) != 0) || (row == -1)) { return true; TableCellRenderer tcr = table.getCellRenderer(row, column); Object value = table.getValueAt(row, column); Component cell = tcr.getTableCellRendererComponent(table, value, false, false, row, column); Dimension itemSize = cell.getPreferredSize(); Rectangle cellBounds = table.getCellRect(row, column, false); ... |
void | setSize(JTable table, int columnIndex, int newSize) set Size TableColumn column = table.getColumnModel().getColumn(columnIndex); setSize(table, column, newSize); |