本文整理汇总了Java中javax.swing.table.TableColumn类的典型用法代码示例。如果您正苦于以下问题:Java TableColumn类的具体用法?Java TableColumn怎么用?Java TableColumn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TableColumn类属于javax.swing.table包,在下文中一共展示了TableColumn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processTableColumn
import javax.swing.table.TableColumn; //导入依赖的package包/类
@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);
}
}
示例2: tableChanged
import javax.swing.table.TableColumn; //导入依赖的package包/类
@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;
}
}
示例3: setupColumns
import javax.swing.table.TableColumn; //导入依赖的package包/类
@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)));
}
示例4: getCellRenderer
import javax.swing.table.TableColumn; //导入依赖的package包/类
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;
}
示例5: clearSortedColumns
import javax.swing.table.TableColumn; //导入依赖的package包/类
/**
* 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);
}
}
示例6: recreateTableColumn
import javax.swing.table.TableColumn; //导入依赖的package包/类
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]);
}
}
示例7: writeRecords
import javax.swing.table.TableColumn; //导入依赖的package包/类
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);
}
}
}
}
示例8: getAvailableColumnNames
import javax.swing.table.TableColumn; //导入依赖的package包/类
/**
* 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()]);
}
示例9: setColumnWidths
import javax.swing.table.TableColumn; //导入依赖的package包/类
/**
* 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;
}
}
}
示例10: columnAdded
import javax.swing.table.TableColumn; //导入依赖的package包/类
@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);
}
示例11: getColumnGroups
import javax.swing.table.TableColumn; //导入依赖的package包/类
/**
* 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;
}
示例12: getPreferredScrollableViewportSize
import javax.swing.table.TableColumn; //导入依赖的package包/类
@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;
}
示例13: autoResizeColWidth
import javax.swing.table.TableColumn; //导入依赖的package包/类
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;
}
示例14: fireTableColumnChanged
import javax.swing.table.TableColumn; //导入依赖的package包/类
/** 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));
}
示例15: getSize
import javax.swing.table.TableColumn; //导入依赖的package包/类
/**
* 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);
}