本文整理汇总了Java中org.jdesktop.swingx.table.TableColumnExt类的典型用法代码示例。如果您正苦于以下问题:Java TableColumnExt类的具体用法?Java TableColumnExt怎么用?Java TableColumnExt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TableColumnExt类属于org.jdesktop.swingx.table包,在下文中一共展示了TableColumnExt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setColumnCollapsed
import org.jdesktop.swingx.table.TableColumnExt; //导入依赖的package包/类
@Override
public void setColumnCollapsed(Column column, boolean collapsed) {
if (!getColumnControlVisible()) {
return;
}
checkNotNullArgument(column, "column must be non null");
if (column.isCollapsed() != collapsed) {
column.setCollapsed(collapsed);
}
TableColumn tableColumn = getColumn(column);
if (tableColumn instanceof TableColumnExt) {
((TableColumnExt) tableColumn).setVisible(!collapsed);
}
}
示例2: configureSorterProperties
import org.jdesktop.swingx.table.TableColumnExt; //导入依赖的package包/类
/**
* Propagates sort-related properties from table/columns to the sorter if it
* is of type SortController, does nothing otherwise.
*
*/
protected void configureSorterProperties() {
// need to hack: if a structureChange is the result of a setModel
// the rowsorter is not yet updated
if (ignoreAddColumn || (!getControlsSorterProperties())) return;
getSortController().setStringValueProvider(getStringValueRegistry());
// configure from table properties
getSortController().setSortable(sortable);
getSortController().setSortsOnUpdates(sortsOnUpdates);
getSortController().setSortOrderCycle(getSortOrderCycle());
// configure from column properties
List<TableColumn> columns = getColumns(true);
for (TableColumn tableColumn : columns) {
int modelIndex = tableColumn.getModelIndex();
getSortController().setSortable(modelIndex,
tableColumn instanceof TableColumnExt ?
((TableColumnExt) tableColumn).isSortable() : true);
getSortController().setComparator(modelIndex,
tableColumn instanceof TableColumnExt ?
((TableColumnExt) tableColumn).getComparator() : null);
}
}
示例3: getColumnExt
import org.jdesktop.swingx.table.TableColumnExt; //导入依赖的package包/类
/**
* Returns the first <code>TableColumnExt</code> with the given
* <code>identifier</code>. The return value is null if there is no
* contained column with <b>identifier</b> or if the column with
* <code>identifier</code> is not of type <code>TableColumnExt</code>. The
* returned column may be visible or hidden.
*
* @param identifier the object used as column identifier
* @return first <code>TableColumnExt</code> with the given identifier or
* null if none is found
*
* @see #getColumnExt(int)
* @see #getColumn(Object)
* @see TableColumnModelExt#getColumnExt(Object)
*/
public TableColumnExt getColumnExt(Object identifier) {
if (getColumnModel() instanceof TableColumnModelExt) {
return ((TableColumnModelExt) getColumnModel())
.getColumnExt(identifier);
} else {
// PENDING: not tested!
try {
TableColumn column = getColumn(identifier);
if (column instanceof TableColumnExt) {
return (TableColumnExt) column;
}
} catch (Exception e) {
// TODO: handle exception
}
}
return null;
}
示例4: createAndAddColumns
import org.jdesktop.swingx.table.TableColumnExt; //导入依赖的package包/类
/**
* Creates and adds <code>TableColumn</code>s for each column of the table
* model.
* <p>
*
*
*/
private void createAndAddColumns() {
/*
* PENDING: go the whole distance and let the factory decide which model
* columns to map to view columns? That would introduce an collection
* managing operation into the factory, sprawling? Can't (and probably
* don't want to) move all collection related operations over - the
* ColumnFactory relies on TableColumnExt type columns, while the
* JXTable has to cope with all the base types.
*/
for (int i = 0; i < getModel().getColumnCount(); i++) {
// add directly to columnModel - don't go through this.addColumn
// to guarantee full control of ColumnFactory
// addColumn has the side-effect to set the header!
TableColumnExt tableColumn = getColumnFactory()
.createAndConfigureTableColumn(getModel(), i);
if (tableColumn != null) {
getColumnModel().addColumn(tableColumn);
}
}
}
示例5: testSetColumnSequence
import org.jdesktop.swingx.table.TableColumnExt; //导入依赖的package包/类
/**
* Issue #1422-swingx: setColumnSequence works incorrectly
*/
@Test
public void testSetColumnSequence() {
int numColumns = 5;
JXTable table = new JXTable(10, numColumns);
//hide first column
TableColumnExt columnExt = table.getColumnExt(0);
columnExt.setVisible(false);
List<TableColumn> allColumns = table.getColumns(true);
List<Object> identifiers = new ArrayList<Object>();
for (TableColumn tableColumn : allColumns) {
identifiers.add(tableColumn.getIdentifier());
}
Collections.reverse(identifiers);
table.setColumnSequence(identifiers.toArray());
assertEquals(numColumns, table.getColumnCount(true));
assertEquals(false, columnExt.isVisible());
assertEquals(numColumns -1, table.getColumnCount());
}
示例6: testStringValueRegistryFromColumnFactory
import org.jdesktop.swingx.table.TableColumnExt; //导入依赖的package包/类
/**
* Issue 1145-swingx: re-enable filter to use string representation.
* Here: test that cell-location StringValue look up initial per-column renderer
*
*/
@Test
public void testStringValueRegistryFromColumnFactory() {
JXTable table = new JXTable();
final int column = 2;
// custom column factory which sets per-column renderer
ColumnFactory factory = new ColumnFactory() {
@Override
public void configureTableColumn(TableModel model,
TableColumnExt columnExt) {
super.configureTableColumn(model, columnExt);
if (columnExt.getModelIndex() == column)
columnExt.setCellRenderer(new DefaultTableRenderer());
}
};
table.setColumnFactory(factory);
table.setModel(createModelDefaultColumnClasses(4));
StringValueRegistry provider = table.getStringValueRegistry();
assertEquals(table.getCellRenderer(0, column), provider.getStringValue(0, column));
}
示例7: assertSortableColumnState
import org.jdesktop.swingx.table.TableColumnExt; //导入依赖的package包/类
public void assertSortableColumnState(JXTable table) {
List<TableColumn> columns = table.getColumns(true);
for (TableColumn tableColumn : columns) {
int i = tableColumn.getModelIndex();
assertEquals("odd/even columns must be not/-sortable: " + i, i % 2 == 0,
getSortController(table).isSortable(i));
if (tableColumn instanceof TableColumnExt) {
Comparator<?> comparator = ((TableColumnExt) tableColumn).getComparator();
// JW: need to check against null because sorter might have its own
// ideas about default comparators
if (comparator != null) {
assertSame("comparator must be same: " + i, comparator,
getSortController(table).getComparator(i));
}
}
}
}
示例8: testPrefColumnsDuplicateMargin
import org.jdesktop.swingx.table.TableColumnExt; //导入依赖的package包/类
/**
* Issue #547-swingx: columns' pref width - added margin twice
* if has prototype.
*
* PENDING: the default initialize is working as expected only
* if the config is done before setting the model, that is
* in the ColumnFactory. Need public api to programatically
* trigger the init after the fact?
*/
@Test
public void testPrefColumnsDuplicateMargin() {
JXTable table = new JXTable(new AncientSwingTeam());
TableColumnExt columnExt = table.getColumnExt(0);
// force the prototype longer than the title
// to avoid that header measuring is triggered
// header renderer can have bigger fonts
columnExt.setPrototypeValue(columnExt.getTitle() + "longer");
TableCellRenderer renderer = table.getCellRenderer(0, 0);
Component comp = renderer.getTableCellRendererComponent(null, columnExt.getPrototypeValue(), false, false, -1, -1);
// make sure the column pref is initialized
table.initializeColumnWidths();
assertEquals("column margin must be added once", table.getColumnMargin(),
columnExt.getPreferredWidth() - comp.getPreferredSize().width);
}
示例9: testTableCanceledEditOnColumnEditableChange
import org.jdesktop.swingx.table.TableColumnExt; //导入依赖的package包/类
/**
* Issue 372-swingx: table must cancel edit if column property
* changes to not editable.
* Here we test if the table actually canceled the edit.
*/
@Test
public void testTableCanceledEditOnColumnEditableChange() {
JXTable table = new JXTable(10, 2);
TableColumnExt columnExt = table.getColumnExt(0);
table.editCellAt(0, 0);
// sanity
assertTrue(table.isEditing());
assertEquals(0, table.getEditingColumn());
TableCellEditor editor = table.getCellEditor();
CellEditorReport report = new CellEditorReport();
editor.addCellEditorListener(report);
columnExt.setEditable(false);
// sanity
assertFalse(table.isCellEditable(0, 0));
assertEquals("editor must have fired canceled", 1, report.getCanceledEventCount());
assertEquals("editor must not have fired stopped",0, report.getStoppedEventCount());
}
示例10: columnPropertyChange
import org.jdesktop.swingx.table.TableColumnExt; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* Listens to column property changes.
*
*/
public void columnPropertyChange(PropertyChangeEvent event) {
if (event.getPropertyName().equals("editable")) {
updateEditingAfterColumnChanged((TableColumn) event.getSource(),
(Boolean) event.getNewValue());
} else if (event.getPropertyName().equals("sortable")) {
updateSortingAfterColumnChanged((TableColumn) event.getSource(),
(Boolean) event.getNewValue());
} else if (event.getPropertyName().startsWith("highlighter")) {
if (event.getSource() instanceof TableColumnExt && getRowCount() > 0) {
TableColumnExt column = (TableColumnExt) event.getSource();
Rectangle r = getCellRect(0,
convertColumnIndexToView(column.getModelIndex()), true);
r.height = getHeight();
repaint(r);
} else {
repaint();
}
}
}
示例11: interactiveCustomColumnFactory
import org.jdesktop.swingx.table.TableColumnExt; //导入依赖的package包/类
/**
* Issue #1379-swingx: support access to underlying treeTableModel of TreeTableModelAdapter.
*
* Needed f.i. in a custom ColumnFactory to configure the hierarchical column specifically.
*/
public void interactiveCustomColumnFactory() {
JXTreeTable table = new JXTreeTable();
ColumnFactory factory = new ColumnFactory() {
/**
* @inherited <p>
*/
@Override
public void configureTableColumn(TableModel model,
TableColumnExt columnExt) {
super.configureTableColumn(model, columnExt);
if (model instanceof TreeTableModelProvider) {
TreeTableModel treeTableModel = ((TreeTableModelProvider) model).getTreeTableModel();
if (treeTableModel.getHierarchicalColumn() == columnExt.getModelIndex()) {
columnExt.setTitle("Hierarchical: " + columnExt.getTitle());
}
}
}
};
table.setColumnFactory(factory);
table.setTreeTableModel(new FileSystemModel());
showWithScrollingInFrame(table, "custom columnFactory");
}
示例12: interactiveTestColumnResizable
import org.jdesktop.swingx.table.TableColumnExt; //导入依赖的package包/类
/**
* TableColumnExt: user friendly resizable
*
*/
public void interactiveTestColumnResizable() {
final JXTable table = new JXTable(sortableTableModel);
table.setColumnControlVisible(true);
final TableColumnExt priorityColumn = table.getColumnExt("First Name");
JXFrame frame = wrapWithScrollingInFrame(table, "JXTable: Column with Min=Max not resizable");
Action action = new AbstractAction("Toggle MinMax of FirstName") {
@Override
public void actionPerformed(ActionEvent e) {
// user-friendly resizable flag
if (priorityColumn.getMinWidth() == priorityColumn.getMaxWidth()) {
priorityColumn.setMinWidth(50);
priorityColumn.setMaxWidth(150);
} else {
priorityColumn.setMinWidth(100);
priorityColumn.setMaxWidth(100);
}
}
};
addAction(frame, action);
frame.setVisible(true);
}
示例13: bind
import org.jdesktop.swingx.table.TableColumnExt; //导入依赖的package包/类
private void bind() {
// <snip>JXTreeTable column customization
// configure and install a custom columnFactory, arguably data related ;-)
ColumnFactory factory = new ColumnFactory() {
String[] columnNameKeys = { "componentType", "componentName", "componentLocation", "componentSize" };
@Override
public void configureTableColumn(TableModel model,
TableColumnExt columnExt) {
super.configureTableColumn(model, columnExt);
if (columnExt.getModelIndex() < columnNameKeys.length) {
columnExt.setTitle(DemoUtils.getResourceString(TreeTableDemo.class,
columnNameKeys[columnExt.getModelIndex()]));
}
}
};
treeTable.setColumnFactory(factory);
// </snip>
}
示例14: getColumnExt
import org.jdesktop.swingx.table.TableColumnExt; //导入依赖的package包/类
/**
* Returns the first <code>TableColumnExt</code> with the given
* <code>identifier</code>. The return value is null if there is no contained
* column with <b>identifier</b> or if the column with <code>identifier</code> is not
* of type <code>TableColumnExt</code>. The returned column
* may be visible or hidden.
*
* @param identifier the object used as column identifier
* @return first <code>TableColumnExt</code> with the given identifier or
* null if none is found
*
* @see #getColumnExt(int)
* @see #getColumn(Object)
* @see TableColumnModelExt#getColumnExt(Object)
*/
public TableColumnExt getColumnExt(Object identifier) {
if (getColumnModel() instanceof TableColumnModelExt) {
return ((TableColumnModelExt) getColumnModel())
.getColumnExt(identifier);
} else {
// PENDING: not tested!
try {
TableColumn column = getColumn(identifier);
if (column instanceof TableColumnExt) {
return (TableColumnExt) column;
}
} catch (Exception e) {
// TODO: handle exception
}
}
return null;
}
示例15: getSessionState
import org.jdesktop.swingx.table.TableColumnExt; //导入依赖的package包/类
public Object getSessionState(Component c) {
checkComponent(c);
JXTable table = (JXTable) c;
List<ColumnState> columnStates = new ArrayList<ColumnState>();
List<TableColumn> columns = table.getColumns(true);
List<TableColumn> visibleColumns = table.getColumns();
for (TableColumn column : columns) {
columnStates.add(new ColumnState((TableColumnExt) column,
visibleColumns.indexOf(column)));
}
XTableState tableState = new XTableState(columnStates.toArray(new ColumnState[columnStates.size()]));
tableState.setHorizontalScrollEnabled(table.isHorizontalScrollEnabled());
List<? extends SortKey> sortKeys = null;
if (table.getRowSorter() != null) {
sortKeys = table.getRowSorter().getSortKeys();
}
// PENDING: store all!
if ((sortKeys != null) && (sortKeys.size() >0)) {
tableState.setSortKey(sortKeys.get(0));
}
return tableState;
}