@Override protected void processTableColumn(TableColumn column, int col) { super.processTableColumn(column, col); if( col == 2 ) { column.setPreferredWidth(50); } else if( col == 3 ) { column.setPreferredWidth(40); } else { column.setPreferredWidth(200); } }
@Override public void tableChanged(TableModelEvent e) { // update tree column name int modelColumn = getTreeColumnIndex(); if ((e.getFirstRow() <= 0) && (modelColumn != -1) && (getColumnCount() > 0)) { String columnName = getModel().getColumnName(modelColumn); TableColumn aColumn = getColumnModel().getColumn(modelColumn); aColumn.setHeaderValue(columnName); } ignoreClearSelection = true; try { super.tableChanged(e); //#61728 - force update of tree's horizontal scrollbar if( null != getTree() ) { firePropertyChange( "positionX", -1, getPositionX() ); } } finally { ignoreClearSelection = false; } }
@SuppressWarnings("unchecked") private void setupColumns() { ResourceBundle loc = NbBundle.getBundle(DiffTreeTable.class); setPropertyColumns(RevisionNode.COLUMN_NAME_PATH, loc.getString("LBL_DiffTree_Column_Path"), RevisionNode.COLUMN_NAME_DATE, loc.getString("LBL_DiffTree_Column_Time"), RevisionNode.COLUMN_NAME_USERNAME, loc.getString("LBL_DiffTree_Column_Username"), RevisionNode.COLUMN_NAME_MESSAGE, loc.getString("LBL_DiffTree_Column_Message")); setPropertyColumnDescription(RevisionNode.COLUMN_NAME_PATH, loc.getString("LBL_DiffTree_Column_Path_Desc")); setPropertyColumnDescription(RevisionNode.COLUMN_NAME_DATE, loc.getString("LBL_DiffTree_Column_Time_Desc")); setPropertyColumnDescription(RevisionNode.COLUMN_NAME_USERNAME, loc.getString("LBL_DiffTree_Column_Username_Desc")); setPropertyColumnDescription(RevisionNode.COLUMN_NAME_MESSAGE, loc.getString("LBL_DiffTree_Column_Message_Desc")); TableColumnModel model = getOutline().getColumnModel(); if (model instanceof ETableColumnModel) { ((ETableColumnModel) model).setColumnHidden(model.getColumn(1), true); } setDefaultColumnSizes(); TableColumn column = getOutline().getColumn(loc.getString("LBL_DiffTree_Column_Message")); column.setCellRenderer(new MessageRenderer(getOutline().getDefaultRenderer(String.class))); }
public TableCellRenderer getCellRenderer(int row, int column) { TableColumn tableColumn = getColumnModel().getColumn(column); TableCellRenderer renderer = tableColumn.getCellRenderer(); if (renderer == null) { Class<?> c = getColumnClass(column); if( c.equals(Object.class) ) { Object o = getValueAt(row,column); if( o != null ) c = getValueAt(row,column).getClass(); } renderer = getDefaultRenderer(c); } return renderer; }
/** * Makes the whole table unsorted except for one column. */ @SuppressWarnings("deprecation") void clearSortedColumns(TableColumn notThisOne) { boolean wasSorted = sortedColumns.contains(notThisOne); for (Iterator it = sortedColumns.iterator(); it.hasNext(); ) { Object o = it.next(); if ((o instanceof ETableColumn) && (o != notThisOne)) { ETableColumn etc = (ETableColumn)o; etc.setSorted(0, false); } } sortedColumns = new ArrayList<TableColumn>(); if (wasSorted) { sortedColumns.add(notThisOne); } }
protected void recreateTableColumn(TableColumnModel columnModel) { int n = columnModel.getColumnCount(); EditableTableHeaderColumn[] newCols = new EditableTableHeaderColumn[n]; TableColumn[] oldCols = new TableColumn[n]; for (int i = 0; i < n; i++) { oldCols[i] = columnModel.getColumn(i); newCols[i] = new EditableTableHeaderColumn(i); newCols[i].copyValues(oldCols[i]); } for (int i = 0; i < n; i++) { columnModel.removeColumn(oldCols[i]); } for (int i = 0; i < n; i++) { columnModel.addColumn(newCols[i]); } }
private void writeRecords(LittleEndianOutputStream dos, Table table) throws IOException { int columnsCount = table.getColumnCount(); int rowsCount = table.getRowCount(); for (int row = 0; row < rowsCount; row++) { // write deleted flag dos.write(' '); for (int col = 0; col < columnsCount; col++) { TableColumn tc = table.getColumn(col); if (table.isDoubleColumn(col)) { final Double d = (Double)table.getValueAt(row, col); String nbrStr = ika.utils.NumberFormatter.format( d.doubleValue(), NUMBER_LENGTH, NUMBER_DECIMALS); this.writeString(dos, nbrStr, NUMBER_LENGTH); } else { String str = (String)table.getValueAt(row, col); this.writeString(dos, str, STRING_LENGTH); } } } }
/** * Computes the strings shown to the user in the selection dialog. */ private static String[] getAvailableColumnNames(ETable table, boolean visibleOnly) { TableColumnModel columnModel = table.getColumnModel(); if (! (columnModel instanceof ETableColumnModel)) { return new String[0]; } final ETableColumnModel etcm = (ETableColumnModel)columnModel; List<TableColumn> columns; if (visibleOnly) { columns = Collections.list(etcm.getColumns()); } else { columns = etcm.getAllColumns(); } Collections.sort(columns, ETableColumnComparator.DEFAULT); ArrayList<String> displayNames = new ArrayList<String>(); for (Iterator<TableColumn> it = columns.iterator(); it.hasNext(); ) { final ETableColumn etc = (ETableColumn)it.next(); String dName = table.getColumnDisplayName(etc.getHeaderValue().toString()); displayNames.add(dName); } Collections.sort(displayNames, Collator.getInstance()); return displayNames.toArray(new String[displayNames.size()]); }
/** * Adjust column widths */ private void setColumnWidths() { TableColumn column = null; for (int i = 0; i < actionsTable.getColumnCount(); i++) { column = actionsTable.getColumnModel().getColumn(i); switch (i) { case 0: column.setPreferredWidth(250); break; case 1: column.setPreferredWidth(175); break; case 2: column.setPreferredWidth(60); break; case 3: column.setPreferredWidth(60); break; } } }
@Override public void columnAdded(TableColumnModelEvent e) { LinesTableColumn type = getColumnType(e.getToIndex()); TableColumn column = getColumnModel().getColumn(e.getToIndex()); switch (type) { case COLOR: column.setMaxWidth(25); break; case CLASS: column.setPreferredWidth(90); break; case STATION: column.setPreferredWidth(90); break; case ALGORITHM: column.setPreferredWidth(100); break; } super.columnAdded(e); }
/** * Get the ColumnGroup list containing the required table * column. * * @param g vector to populate with the ColumnGroup/s * @param c TableColumn * @return Vector containing the ColumnGroup/s */ @SuppressWarnings("unchecked") public Vector<Object> getColumnGroups(TableColumn c, Vector<Object> g) { g.addElement(this); if (v.contains(c)) return g; Iterator iter = v.iterator(); while (iter.hasNext()) { Object obj = iter.next(); if (obj instanceof ColumnGroup) { Vector groups = ((ColumnGroup) obj).getColumnGroups(c, (Vector) g.clone()); if (groups != null) return groups; } } return null; }
@Override public Dimension getPreferredScrollableViewportSize() { if( needCalcRowHeight ) { calcRowHeight( getOffscreenGraphics() ); prefSize = null; } if( null == prefSize ) { Dimension dim = new Dimension(); for( int i=0; i<getColumnCount(); i++ ) { TableColumn tc = getColumnModel().getColumn( i ); dim.width += tc.getPreferredWidth(); } int rowCount = Math.min( MAX_VISIBLE_ROWS, getRowCount() ); dim.height = rowCount*getRowHeight(); Rectangle screen = Utilities.getUsableScreenBounds(); dim.width = Math.min( dim.width, screen.width-100 ); dim.height = Math.min( dim.height, screen.height-100 ); prefSize = dim; } return prefSize; }
public static JTable autoResizeColWidth(JTable table, int extraSpaceToColumn) { if (extraSpaceToColumn < 0 || extraSpaceToColumn >= table.getColumnCount()) { throw new IllegalArgumentException("Illegal Column index. Table " + table.getName() + " has " + table.getColumnCount() + " columns. Can't set extra space to column " + extraSpaceToColumn); } int totalWidth = autoResizeColWidthNoFill(table); int availableWidth = table.getParent().getWidth(); if (totalWidth >= availableWidth) { return table; } int increaseBy = availableWidth - totalWidth; DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel(); TableColumn col = colModel.getColumn(extraSpaceToColumn); int oldWidth = col.getPreferredWidth(); col.setPreferredWidth(oldWidth + increaseBy); return table; }
/** Fires a TableModelEvent - change of one column */ public void fireTableColumnChanged(int index) { int columnModelIndex = index; // reset the header value as well Object list[] = listenerList.getListenerList(); for (int i = 0; i < list.length; i++) { if (list[i] instanceof JTable) { JTable jt = (JTable)list[i]; try { TableColumn column = jt.getColumnModel().getColumn(index); columnModelIndex = column.getModelIndex(); column.setHeaderValue(jt.getModel().getColumnName(columnModelIndex)); } catch (ArrayIndexOutOfBoundsException abe) { // only catch exception } jt.getTableHeader().repaint(); } } fireTableChanged(new TableModelEvent(this, 0, getRowCount() - 1, columnModelIndex)); }
/** * Get the dimension of this ColumnGroup. * * @param table the table the header is being rendered in * @return the dimension of the ColumnGroup */ @SuppressWarnings("unchecked") public Dimension getSize(JTable table) { Component comp = renderer.getTableCellRendererComponent( table, getHeaderValue(), false, false, -1, -1); int height = comp.getPreferredSize().height; int width = 0; Iterator iter = v.iterator(); while (iter.hasNext()) { Object obj = iter.next(); if (obj instanceof TableColumn) { TableColumn aColumn = (TableColumn) obj; width += aColumn.getWidth(); } else { width += ((ColumnGroup) obj).getSize(table).width; } } return new Dimension(width, height); }
/*** * Intercept changes to model so we can re-add our columns * @param e the table event */ @Override public void tableChanged(TableModelEvent e) { if (e == null || e.getFirstRow() == TableModelEvent.HEADER_ROW) { TableColumnModel tcm = getColumnModel(); TableModel m = getModel(); if (m != null) { // Remove any current columns while (tcm.getColumnCount() > 0) { tcm.removeColumn(tcm.getColumn(0)); } // Create new columns from the data model info for (int ii = startModelColumn; ii < m.getColumnCount() && ii < endModelColumn; ii++) { TableColumn newColumn = new TableColumn(ii); addColumn(newColumn); } } } super.tableChanged(e); }
/** * Constructor. */ public RowHeader() { Table.this.addPropertyChangeListener(this); // row header should not allow to sort. setSortable(false); setFocusable(false); setAutoCreateColumnsFromModel(false); setModel(Table.this.getModel()); setSelectionModel(Table.this.getSelectionModel()); TableColumn column = new TableColumn(); column.setHeaderValue(" "); addColumn(column); column.setCellRenderer(new RowNumberRenderer()); getColumnModel().getColumn(0).setPreferredWidth(50); setPreferredScrollableViewportSize(getPreferredSize()); }
private void setTableModel() { LocalVariableTableAttribTableModel localLocalVariableTableAttribTableModel = new LocalVariableTableAttribTableModel(this.attribute, this.constPool); checkForObfuscation(); localLocalVariableTableAttribTableModel.setEditable(this.bModifyMode); this.tblLocalVariables.setModel(localLocalVariableTableAttribTableModel); localLocalVariableTableAttribTableModel.setCellEditors(this.tblLocalVariables); TableColumn localTableColumn = this.tblLocalVariables.getColumnModel().getColumn(0); localTableColumn.setPreferredWidth(30); localTableColumn.setMaxWidth(80); localTableColumn = this.tblLocalVariables.getColumnModel().getColumn(1); localTableColumn.setPreferredWidth(200); localTableColumn.setMaxWidth(400); localTableColumn = this.tblLocalVariables.getColumnModel().getColumn(2); localTableColumn.setPreferredWidth(200); localTableColumn.setMaxWidth(400); localTableColumn = this.tblLocalVariables.getColumnModel().getColumn(3); localTableColumn.setPreferredWidth(50); localTableColumn.setMaxWidth(200); localTableColumn = this.tblLocalVariables.getColumnModel().getColumn(4); localTableColumn.setPreferredWidth(50); localTableColumn.setMaxWidth(200); this.tblLocalVariables.changeSelection(0, 1, false, false); }
/** */ public void setObject (Object obj) { peer = (TreeNamedObjectMap) obj; tableModel = new AttlistTableModel(/*peer*/); attrTable.setModel(tableModel); // attrTable.addKeyListener(new RowKeyListener(attrTable)); // DTD is read only now --> it will be ready in future /** First table column is row selector. */ TableColumn column = null; for (int i = 0; i < COL_COUNT; i++) { column = attrTable.getColumnModel().getColumn (i); column.setPreferredWidth (50); } updateView (peer); peer.addPropertyChangeListener (org.openide.util.WeakListeners.propertyChange (this, peer)); }
private void setExceptionTableModel() { CodeExceptionsListTableModel localCodeExceptionsListTableModel = new CodeExceptionsListTableModel(this.constPool, this.attribute); this.tblExceptions.setModel(localCodeExceptionsListTableModel); localCodeExceptionsListTableModel.setEditable(this.bModifyMode); localCodeExceptionsListTableModel.setCellEditors(this.tblExceptions); TableColumn localTableColumn = this.tblExceptions.getColumnModel().getColumn(0); localTableColumn.setPreferredWidth(30); localTableColumn.setMaxWidth(80); localTableColumn = this.tblExceptions.getColumnModel().getColumn(1); localTableColumn.setPreferredWidth(300); localTableColumn.setMaxWidth(500); localTableColumn = this.tblExceptions.getColumnModel().getColumn(2); localTableColumn.setPreferredWidth(100); localTableColumn.setMaxWidth(150); localTableColumn = this.tblExceptions.getColumnModel().getColumn(3); localTableColumn.setPreferredWidth(100); localTableColumn.setMaxWidth(150); localTableColumn = this.tblExceptions.getColumnModel().getColumn(4); localTableColumn.setPreferredWidth(100); localTableColumn.setMaxWidth(150); }
public TableColumn addColumn(Object columnIdentifier, int width, TableCellRenderer renderer, TableCellEditor editor, List columnData) { checkDefaultTableModel(); // Set up the model side first DefaultTableModel m = (DefaultTableModel)getModel(); m.addColumn(columnIdentifier, columnData.toArray()); // The column will have been added to the end, so the index of the // column in the model is the last element. TableColumn newColumn = new TableColumn( m.getColumnCount()-1, width, renderer, editor); super.addColumn(newColumn); return newColumn; }
public void setUpSportColumn(JTable table, TableColumn sportColumn) { // Set up the editor for the sport cells. JComboBox comboBox = new JComboBox(); comboBox.addItem("Snowboarding"); comboBox.addItem("Rowing"); comboBox.addItem("Knitting"); comboBox.addItem("Speed reading"); comboBox.addItem("Pool"); comboBox.addItem("None of the above"); sportColumn.setCellEditor(new DefaultCellEditor(comboBox)); // Set up tool tips for the sport cells. DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setToolTipText("Click for combo box"); sportColumn.setCellRenderer(renderer); }
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel classNameLabel = new JLabel( ((Class<?>) value).getSimpleName()); table.setRowHeight(row, Math.max(table.getRowHeight(row), (int) classNameLabel.getPreferredSize().getHeight())); TableColumn cm = table.getColumnModel().getColumn(column); cm.setMinWidth(Math.max(cm.getMinWidth(), (int) classNameLabel .getMinimumSize().getWidth())); return classNameLabel; }
private void setOutlineColumns() { if (details) { outlineView.addPropertyColumn( "detailsCount", UiUtils.getText( //NOI18N "BasicSearchResultsPanel.outline.detailsCount"), //NOI18N UiUtils.getText( "BasicSearchResultsPanel.outline.detailsCount.desc"));//NOI18N } outlineView.addPropertyColumn("path", UiUtils.getText( "BasicSearchResultsPanel.outline.path"), //NOI18N UiUtils.getText( "BasicSearchResultsPanel.outline.path.desc")); //NOI18N outlineView.addPropertyColumn("size", UiUtils.getText( "BasicSearchResultsPanel.outline.size"), //NOI18N UiUtils.getText( "BasicSearchResultsPanel.outline.size.desc")); //NOI18N outlineView.addPropertyColumn("lastModified", UiUtils.getText( "BasicSearchResultsPanel.outline.lastModified"),//NOI18N UiUtils.getText( "BasicSearchResultsPanel.outline.lastModified.desc")); //NOI18N outlineView.getOutline().setAutoResizeMode( Outline.AUTO_RESIZE_SUBSEQUENT_COLUMNS); this.columnModel = (ETableColumnModel) outlineView.getOutline().getColumnModel(); Enumeration<TableColumn> cols = columnModel.getColumns(); while (cols.hasMoreElements()) { allColumns.add(cols.nextElement()); } loadColumnState(); outlineView.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); }
/** * setting up the table. * * @param table JTable to store this.correlationTableModel */ private void setupBasicTableProperties(JTable table) { table.clearSelection(); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); TableRenderer cellRenderer = new TableRenderer(new JTextField()); table.setRowSelectionAllowed(true); table.setColumnSelectionAllowed(false); table.setVisible(true); table.setModel(this.variationPerParameterTableModel); initColumnSizes(table); for (int i = 0; i < table.getColumnCount(); i++) { TableColumn column = table.getColumnModel().getColumn(i); column.setCellRenderer(cellRenderer); } TableColumn columnName = table.getColumnModel().getColumn(VariationPerParameterTableModel.COLUMN_NAME); columnName.setCellEditor(new TextCellEditor()); TableColumn columnBasicValue = table.getColumnModel().getColumn(VariationPerParameterTableModel.COLUMN_BASIC_VALUE); columnBasicValue.setCellEditor(new TextCellEditor()); setupVariationFunctionComboBoxColumn(); this.variationPerParameterTableModel.fireTableDataChanged(); table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true); //select first row. table.getSelectionModel().setSelectionInterval(0, 0); }
public static void getJTableOptions(final String name, final JTable table, final Properties properties) { final Integer colCount = getObjectInteger(name + "_col_count", properties); if (colCount == null || colCount.intValue() != table.getColumnCount()) return; final String cNames[] = new String[table.getColumnCount()]; final Object cols[] = new Object[table.getColumnCount()]; for (int i = 0; i < cNames.length; i++) { cNames[i] = table.getColumnName(i); cols[i] = table.getColumnModel().getColumn(i); } for (final String element : cNames) { final int width = getInteger(name + "_col_" + element + "_width", table.getColumn(element).getWidth(), properties); table.getColumn(element).setPreferredWidth(width); } final TableColumnModel cm = table.getColumnModel(); final int tci[] = new int[cNames.length]; for (int i = 0; i < cNames.length; i++) cm.removeColumn((TableColumn) cols[i]); for (int i = 0; i < cNames.length; i++) { tci[i] = getInteger(name + "_col_" + cNames[i] + "_index", i, properties); } for (int i = 0; i < cNames.length; i++) for (int j = 0; j < cNames.length; j++) if (tci[j] == i) cm.addColumn((TableColumn) cols[j]); }
/** * Erzeugt die Tabelle für die Anzeige der Medien. */ private void erzeugeMedienTable() { JScrollPane medienAuflisterScrollPane = new JScrollPane(); medienAuflisterScrollPane.setBorder(BorderFactory.createTitledBorder( null, "Medien", TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION, UIConstants.HEADER_FONT)); medienAuflisterScrollPane.setBackground(UIConstants.BACKGROUND_COLOR); medienAuflisterScrollPane.getVerticalScrollBar() .setBackground(UIConstants.BACKGROUND_COLOR); medienAuflisterScrollPane.getHorizontalScrollBar() .setBackground(UIConstants.BACKGROUND_COLOR); _ausleiheMedienTableModel = new AusleiheMedienTableModel(); _medienTable = new JTable(); medienAuflisterScrollPane.setViewportView(_medienTable); _medienTable.setModel(_ausleiheMedienTableModel); JTableHeader tableHeader = _medienTable.getTableHeader(); tableHeader.setFont(UIConstants.HEADER_FONT); tableHeader.setReorderingAllowed(false); tableHeader.setResizingAllowed(false); _medienTable.setFont(UIConstants.TEXT_FONT); // Text in der 3. Spalte mittig ausrichten DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setHorizontalAlignment(JLabel.CENTER); String columnName = _medienTable.getColumnName(2); TableColumn column = _medienTable.getColumn(columnName); column.setCellRenderer(renderer); _hauptPanel.add(medienAuflisterScrollPane, BorderLayout.CENTER); }
private void removeColumn(TableColumn column, boolean doShift) { if (sortedColumns.remove(column)) { int i = 1; for (TableColumn sc : sortedColumns) { if (sc instanceof ETableColumn) { ETableColumn etc = (ETableColumn) sc; etc.setSorted(i, etc.isAscending()); } i++; } } if (removeHiddenColumn(column, doShift) < 0) { int columnIndex = tableColumns.indexOf(column); super.removeColumn(column); if (doShift) { int n = hiddenColumnsPosition.size(); for (int i = 0; i < n; i++) { if (hiddenColumnsPosition.get(i) <= columnIndex) { columnIndex++; } } for (int i = 0; i < n; i++) { int index = hiddenColumnsPosition.get(i); if (index > columnIndex) { hiddenColumnsPosition.set(i, --index); } } } } }
/** Copy of addColumn(TableColumn) with an index specifying where to add the new column */ private void addColumn(TableColumn aColumn, int index) { if (aColumn == null) { throw new IllegalArgumentException("Object is null"); } tableColumns.insertElementAt(aColumn, index); aColumn.addPropertyChangeListener(this); //invalidateWidthCache(); totalColumnWidth = -1; // Post columnAdded event notification fireColumnAdded(new TableColumnModelEvent(this, 0, index)); }
/** Get all columns, including hidden ones. */ List<TableColumn> getAllColumns() { List<TableColumn> columns = Collections.list(getColumns()); int n = hiddenColumns.size(); for (int i = 0; i < n; i++) { int index = hiddenColumnsPosition.get(i); index = Math.min(index, columns.size()); columns.add(index, hiddenColumns.get(i)); } return columns; }
/** * Makes the whole table unsorted. */ @SuppressWarnings("deprecation") public void clearSortedColumns() { for (Iterator it = sortedColumns.iterator(); it.hasNext(); ) { Object o = it.next(); if (o instanceof ETableColumn) { ETableColumn etc = (ETableColumn)o; etc.setSorted(0, false); } } sortedColumns = new ArrayList<TableColumn>(); }
public TableCellEditor getCellEditor(int row, int column) { TableColumn tableColumn = getColumnModel().getColumn(column); TableCellEditor editor = tableColumn.getCellEditor(); if (editor == null) { Class<?> c = getColumnClass(column); if( c.equals(Object.class) ) { Object o = getValueAt(row,column); if( o != null ) c = getValueAt(row,column).getClass(); } editor = getDefaultEditor(c); } return editor; }
/** * Test of createColumn method, of class org.netbeans.swing.etable.ETable. */ public void testCreateColumn() { System.out.println("testCreateColumn"); final boolean [] called = new boolean[1]; ETable t = new ETable(1, 1) { public TableColumn createColumn(int index){ TableColumn tc = super.createColumn(index); called[0] = tc instanceof ETableColumn; return tc; } }; assertTrue("createColumn should have been called and returned correct type", called[0]); }
private static void checkColumnOrder(ETableColumnModel etcm, String names) { List<TableColumn> allColumns = etcm.getAllColumns(); StringBuilder sb = new StringBuilder(); for (TableColumn c : allColumns) { sb.append(c.getHeaderValue().toString()); } assertEquals("All column names:", names, sb.toString()); }
/** * This method picks good column sizes. If all column headers are wider than * the column's cells' contents, then just use column.sizeWidthToFit(). * @param table Selected Results Table */ public void initColumnSizes(JTable table) { TableColumn column; Component comp; int headerWidth; int cellWidth; TableCellRenderer headerRenderer = table.getTableHeader() .getDefaultRenderer(); // TODO: move to tableModel. AK for (int i = 0; i < this.resultsTableModel.getColumnCount(); i++) { column = table.getColumnModel().getColumn(i); comp = headerRenderer.getTableCellRendererComponent(null, column .getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; // /TODO: move to tableModel. AK comp = table.getDefaultRenderer(this.resultsTableModel.getColumnClass(i)) .getTableCellRendererComponent(table, this.resultsTableModel.longValues[i], false, false, 0, i); cellWidth = comp.getPreferredSize().width; // XXX: Before Swing 1.1 Beta 2, use setMinWidth instead. column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } }
private void populateExceptions() { ExceptionsListTableModel localExceptionsListTableModel = new ExceptionsListTableModel(this.constPool, this.attribute); this.tblExceptions.setModel(localExceptionsListTableModel); localExceptionsListTableModel.setEditable(this.bModifyMode); localExceptionsListTableModel.setCellEditors(this.tblExceptions); TableColumn localTableColumn = this.tblExceptions.getColumnModel().getColumn(0); localTableColumn.setPreferredWidth(30); localTableColumn.setMaxWidth(80); localTableColumn = this.tblExceptions.getColumnModel().getColumn(1); localTableColumn.setPreferredWidth(500); localTableColumn.setMaxWidth(800); }
void initColumsWidth() { for (int i = 0; i < 4; i++) { TableColumn column = getColumnModel().getColumn(i); if (i == 0) { column.setPreferredWidth(32767); } else { column.setMinWidth(100); column.setPreferredWidth(100); } } }
@Override final public void mouseClicked(MouseEvent objPmouseEvent) { if (objPmouseEvent.getClickCount() == 2) { final JTableHeader objLjTableHeader = (JTableHeader) objPmouseEvent.getSource(); final TableColumn objLtableColumn = this.getResizingColumn(objLjTableHeader, objPmouseEvent.getPoint()); if (objLtableColumn != null) { final int intLcolumnIndex = objLjTableHeader.getColumnModel().getColumnIndex(objLtableColumn.getIdentifier()); ((DataJTable) objLjTableHeader.getTable()).setContentAdjustedColumnWidth(intLcolumnIndex); } } }
private void setColumnWidth(int columnIndex) { TableColumn col = jTableFields.getColumnModel().getColumn(columnIndex); JCheckBox box = new JCheckBox(); int width = (int) box.getPreferredSize().getWidth(); col.setPreferredWidth(width); col.setMinWidth(width); col.setMaxWidth(width); col.setResizable(false); }
private void initTable() { String[] columnNames = {"��Ʒ����", "��Ʒ���", "��Ӧ��", "����", "��λ", "���", "����", "����", "��װ", "����", "���ĺ�"}; ((DefaultTableModel) table.getModel()) .setColumnIdentifiers(columnNames); TableColumn column = table.getColumnModel().getColumn(0); final DefaultCellEditor editor = new DefaultCellEditor(sp); editor.setClickCountToStart(2); column.setCellEditor(editor); }