List of utility methods to do JTable Column
void | hideColumn(JTable table, int columnIndex) hide Column TableColumn column = table.getColumnModel().getColumn(columnIndex); column.setMaxWidth(0); column.setMinWidth(0); column.setResizable(false); column.setPreferredWidth(0); |
void | installDelegatingColumn(TableColumn column, String label) install Delegating Column column.setMaxWidth(new JButton(label).getPreferredSize().width); column.setCellRenderer(new TableCellRenderer() { @Override public JComponent getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { return (JComponent) value; }); ... |
boolean | isColumnDefinitionChange(TableModelEvent e) is Column Definition Change return (e.getFirstRow() == TableModelEvent.HEADER_ROW);
|
boolean | isColumnSorted(JTable table, int column) Returns whether a table column is sorted. boolean isSorted = false; final int modelColumn = table.convertColumnIndexToModel(column); RowSorter sorter = table.getRowSorter(); if (sorter != null) { List<? extends SortKey> sortKeys = sorter.getSortKeys(); for (SortKey sortKey : sortKeys) { if (sortKey.getColumn() == modelColumn) { isSorted = true; ... |
boolean | isNotDuplicateKeyOfTable(String text, TableModel model, int column) is Not Duplicate Key Of Table int rowcount = model.getRowCount(); for (int row = 0; row < rowcount; row++) { if (model.getValueAt(row, column).toString().equals(text)) return false; return true; |
void | layoutColumns(JTable p_Table, boolean p_OnlyVisibleRows) layout Columns int column = 0; TableColumn c = null; int firstRow = p_OnlyVisibleRows ? getFirstVisibleRow(p_Table) : 0; int lastRow = p_OnlyVisibleRows ? getLastVisibleRow(p_Table) : (p_Table.getModel().getRowCount() - 1); Dimension intercellSpacing = p_Table.getIntercellSpacing(); JTableHeader tableHeader = p_Table.getTableHeader(); for (java.util.Enumeration columns = tableHeader.getColumnModel().getColumns(); columns .hasMoreElements(); column++) { ... |
TableModel | loadToTableModel(String fileName, Object[] columns) load To Table Model DefaultTableModel model = new DefaultTableModel(); model.setColumnIdentifiers(columns); FileReader reader = null; try { reader = new FileReader(fileName); BufferedReader buf = new BufferedReader(reader); String line; line = buf.readLine(); ... |
JPanel | makeTablePanel(int rows, int cols, int mainColumn, JComponent components[]) This method creates a JPanel which layouts given components in a table of given rows/columns. GridBagLayout layout = new GridBagLayout(); JPanel panel = new JPanel(layout); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.insets = new Insets(0, 0, 5, 5); for (int row = 0; row < rows; row++) for (int col = 0; col < cols; col++) { constraints.gridx = col; ... |
JTable | newTable(String name, Object[][] rowData, Object[] columnNames) new Table JTable table = new JTable(rowData, columnNames); table.setName(name); return table; |
void | pack(JTable table, boolean packColumns, boolean packRows, int padding) pack final Enumeration<TableColumn> cols = table.getColumnModel().getColumns(); int[] rowHeights = new int[table.getRowCount()]; while (cols.hasMoreElements()) { TableColumn tc = cols.nextElement(); final int colIndex = tc.getModelIndex(); int width = 0; if (packColumns) { TableCellRenderer renderer = tc.getHeaderRenderer(); ... |