Java Code Examples for javax.swing.table.TableColumn#getMinWidth()
The following examples show how to use
javax.swing.table.TableColumn#getMinWidth() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TableUIBridge.java From darklaf with MIT License | 5 votes |
/** * Return the minimum size of the table. The minimum height is the row height times the number of rows. The minimum * width is the sum of the minimum widths of each column. */ public Dimension getMinimumSize(final JComponent c) { long width = 0; Enumeration<TableColumn> enumeration = table.getColumnModel().getColumns(); while (enumeration.hasMoreElements()) { TableColumn aColumn = enumeration.nextElement(); width = width + aColumn.getMinWidth(); } return createTableSize(width); }
Example 2
Source File: EditableTableHeaderColumn.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
public void copyValues(TableColumn base) { modelIndex = base.getModelIndex(); identifier = base.getIdentifier(); width = base.getWidth(); minWidth = base.getMinWidth(); setPreferredWidth(base.getPreferredWidth()); maxWidth = base.getMaxWidth(); headerRenderer = base.getHeaderRenderer(); headerValue = base.getHeaderValue(); cellRenderer = base.getCellRenderer(); cellEditor = base.getCellEditor(); isResizable = base.getResizable(); }
Example 3
Source File: EditableHeaderTableColumn.java From chipster with MIT License | 5 votes |
public void copyValues(TableColumn base) { modelIndex = base.getModelIndex(); identifier = base.getIdentifier(); width = base.getWidth(); minWidth = base.getMinWidth(); setPreferredWidth(base.getPreferredWidth()); maxWidth = base.getMaxWidth(); headerRenderer = base.getHeaderRenderer(); headerValue = base.getHeaderValue(); cellRenderer = base.getCellRenderer(); cellEditor = base.getCellEditor(); isResizable = base.getResizable(); }
Example 4
Source File: TableEditor.java From AndroidDBvieweR with Apache License 2.0 | 4 votes |
public void adjustTable(Component tableContainer, JTable table) { table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); DefaultTableColumnModel defColumnModel = (DefaultTableColumnModel) table.getColumnModel(); int columnCount = table.getColumnCount(); int[] columnWidths = new int[columnCount]; int totalWidth = 0; for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) { TableColumn tableColumn = defColumnModel.getColumn(columnIndex); TableCellRenderer headerRenderer = tableColumn.getHeaderRenderer(); if (headerRenderer == null) { headerRenderer = table.getTableHeader().getDefaultRenderer(); } int minWidth = tableColumn.getMinWidth(); int headerWidth = headerRenderer.getTableCellRendererComponent(table, tableColumn.getHeaderValue(), false, false, -1, columnIndex).getPreferredSize().width; int finalColumnWidth = Math.max(minWidth, headerWidth); for (int rowIndex = 0; rowIndex < table.getRowCount(); rowIndex++) { int rowWidth = table.prepareRenderer(table.getCellRenderer(rowIndex, columnIndex), rowIndex, columnIndex).getPreferredSize().width; finalColumnWidth = Math.max(rowWidth, finalColumnWidth); // Object cellValue = table.getValueAt(rowIndex, columnIndex); // try { // long longValue = (Long) cellValue; // cellTextField.setHorizontalAlignment(JTextField.RIGHT); // } catch (Exception e0) { // try { // double doubleValue = (Double) cellValue; // cellTextField.setHorizontalAlignment(JTextField.RIGHT); // } catch (Exception e1) { // try { // boolean doubleValue = (Boolean) cellValue; // cellTextField.setHorizontalAlignment(JTextField.CENTER); // } catch (Exception e2) { // cellTextField.setHorizontalAlignment(JTextField.LEADING); // } // } // } } columnWidths[columnIndex] = finalColumnWidth; totalWidth += columnWidths[columnIndex]; } int containerWidth = tableContainer.getWidth(); if (totalWidth < containerWidth) { TableColumnModel columnModel = table.getColumnModel(); int rest = containerWidth - totalWidth; int additionalWidth = rest / columnCount; int extraWidth = rest % columnCount; int maxWidthColumnIndex = 0; int maxColumnWidth = 0; for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) { int columnWidth = columnWidths[columnIndex]; if (maxColumnWidth < columnWidth) { maxColumnWidth = columnWidth; maxWidthColumnIndex = columnIndex; } } for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) { columnModel.getColumn(columnIndex).setPreferredWidth(columnWidths[columnIndex] + additionalWidth + (columnIndex == maxWidthColumnIndex ? extraWidth : 0)); } } }
Example 5
Source File: DatabaseController.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
protected void loadDataViewer( QueryResult queryResult ) { if (queryResult == null) { currentDataTable.setModel(new DefaultTableModel()); return; } Object[] names = queryResult.names.toArray(new String[0]); List<Object[]> data = queryResult.data; Object[][] values = new Object[queryResult.data.size()][]; int index = 0; for( Object[] objects : data ) { values[index++] = objects; for( int i = 0; i < objects.length; i++ ) { if (objects[i] instanceof Date) { Date date = (Date) objects[i]; String formatted = DbsUtilities.dbDateFormatter.format(date); objects[i] = formatted; } } } currentDataTable.setModel(new DefaultTableModel(values, names)); currentDataTable.setCellSelectionEnabled(true); for( int column = 0; column < currentDataTable.getColumnCount(); column++ ) { TableColumn tableColumn = currentDataTable.getColumnModel().getColumn(column); int preferredWidth = tableColumn.getMinWidth(); int maxWidth = tableColumn.getMaxWidth(); for( int row = 0; row < currentDataTable.getRowCount(); row++ ) { TableCellRenderer cellRenderer = currentDataTable.getCellRenderer(row, column); Component c = currentDataTable.prepareRenderer(cellRenderer, row, column); int width = c.getPreferredSize().width + currentDataTable.getIntercellSpacing().width; preferredWidth = Math.max(preferredWidth, width); if (preferredWidth >= maxWidth) { preferredWidth = maxWidth; break; } } if (preferredWidth < 50) { preferredWidth = 50; } if (preferredWidth > 300) { preferredWidth = 300; } tableColumn.setPreferredWidth(preferredWidth); } _recordCountTextfield.setText(values.length + " in " + millisToTimeString(queryResult.queryTimeMillis)); }