本文整理了Java中javax.swing.table.TableColumnModel.getColumnIndex()
方法的一些代码示例,展示了TableColumnModel.getColumnIndex()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TableColumnModel.getColumnIndex()
方法的具体详情如下:
包路径:javax.swing.table.TableColumnModel
类名称:TableColumnModel
方法名:getColumnIndex
暂无
代码示例来源:origin: stackoverflow.com
int index = tcm.getColumnIndex(columnName);
TableColumn column = tcm.getColumn(index);
hiddenColumns.put(columnName, column);
代码示例来源:origin: stackoverflow.com
int index = tcm.getColumnIndex(columnName);
TableColumn column = tcm.getColumn(index);
IndexedColumn ic = new IndexedColumn(index, column);
代码示例来源:origin: de.sciss/jtreetable
@Override
public int getColumnIndex(Object columnIdentifier) {
return delegate.getColumnIndex(columnIdentifier);
}
代码示例来源:origin: stackoverflow.com
TableColumnModel model = viewTable.getColumnModel();
int index = -1;
try {
index = model.getColumnIndex("customer Id");
} catch (IllegalArgumentException e) {
// I know, sucks...
}
if (index < 0) {
// Add new column, if JRadioButton.isSelected
} else {
// Remove old column...
// JRadioButton.isSelected is false...
}
代码示例来源:origin: de.sciss/jtreetable
public TableColumn getColumn(Object identifier) {
return columnModel.getColumn(columnModel.getColumnIndex(identifier));
}
代码示例来源:origin: tinyMediaManager/tinyMediaManager
public void hideColumn(Object identifier) {
int index = columnModel.getColumnIndex(identifier);
TableColumn column = columnModel.getColumn(index);
if (hiddenColumns.put(identifier, column) != null) {
throw new IllegalArgumentException("Duplicate column name.");
}
columnModel.removeColumn(column);
}
代码示例来源:origin: girtel/Net2Plan
/**
* Hide a column.
*
* @param columnName Name of the column to hide.
* @since 0.3.0
*/
public void hide(String columnName) {
int index = tcm.getColumnIndex(columnName);
TableColumn column = tcm.getColumn(index);
tcm.removeColumn(column);
}
代码示例来源:origin: openpnp/openpnp
/**
* Convenience method to order the table columns of a table. The columns are ordered based on
* the column names specified in the array. If the column name is not found then no column is
* moved. This means you can specify a null value to preserve the current order of a given
* column.
*
* @param table the table containing the columns to be sorted
* @param columnNames an array containing the column names in the order they should be displayed
*/
public static void reorderColumns(JTable table, Object... columnNames) {
TableColumnModel model = table.getColumnModel();
for (int newIndex = 0; newIndex < columnNames.length; newIndex++) {
try {
Object columnName = columnNames[newIndex];
int index = model.getColumnIndex(columnName);
model.moveColumn(index, newIndex);
}
catch (IllegalArgumentException e) {
}
}
}
} // End of Class RXTable
代码示例来源:origin: org.appdapter/org.appdapter.lib.gui
/**
* Convenience method to order the table columns of a table. The columns
* are ordered based on the column names specified in the array. If the
* column name is not found then no column is moved. This means you can
* specify a null value to preserve the current order of a given column.
*
* @param table the table containing the columns to be sorted
* @param columnNames an array containing the column names in the
* order they should be displayed
*/
public void reorderColumns(JTable table, Object... columnNames) {
TableColumnModel model = table.getColumnModel();
for (int newIndex = 0; newIndex < columnNames.length; newIndex++) {
try {
Object columnName = columnNames[newIndex];
int index = model.getColumnIndex(columnName);
model.moveColumn(index, newIndex);
} catch (IllegalArgumentException e) {
}
}
}
代码示例来源:origin: com.eas.platypus/platypus-js-grid
/**
* {@inheritDoc}
*/
@Override
public int getColumnIndex(Object columnId) {
int delegatedColIndex = delegate.getColumnIndex(columnId);
if (constraint.inConstraint(delegatedColIndex)) {
return constraint.constraint(delegatedColIndex);
} else {
return -1;
}
}
代码示例来源:origin: in.jlibs/org-netbeans-swing-outline
/**
* @returns width in pixels of the graphical representation of the data.
*/
private int estimatedWidth(Object dataObject, JTable table) {
TableCellRenderer cr = getCellRenderer();
if (cr == null) {
Class c = table.getModel().getColumnClass(modelIndex);
cr = table.getDefaultRenderer(c);
}
Component c = cr.getTableCellRendererComponent(table, dataObject, false,
false, 0, table.getColumnModel().getColumnIndex(getIdentifier()));
return c.getPreferredSize().width;
}
代码示例来源:origin: stackoverflow.com
JTableHeader th = table.getTableHeader();
TableColumnModel tcm = th.getColumnModel();
TableColumn tc = tcm.getColumn(tcm.getColumnIndex("Name")); // may not work, see note below
tc.setHeaderValue( "???" );
th.repaint();
代码示例来源:origin: com.eas.platypus/platypus-js-grid
/**
* {@inheritDoc}
*/
@Override
public int getColumnIndex(Object aColumnId) {
for (int i = 0; i < leftInsetColumns.size(); i++) {
Object id = leftInsetColumns.get(i).getIdentifier();
if (id.equals(aColumnId)) {
return i;
}
}
int delegateIndex = delegate.getColumnIndex(aColumnId);
if (delegateIndex >= 0 && delegateIndex < delegate.getColumnCount()) {
return delegateIndex + leftInsetColumns.size();
}
for (int i = 0; i < rightInsetColumns.size(); i++) {
Object id = rightInsetColumns.get(i).getIdentifier();
if (id.equals(aColumnId)) {
return leftInsetColumns.size() + delegate.getColumnCount() + i;
}
}
return -1;
}
代码示例来源:origin: girtel/Net2Plan
@Override
public void mouseClicked(MouseEvent e) {
e.consume();
if (e.getClickCount() == 2) {
JTableHeader header = (JTableHeader) e.getSource();
TableColumn tableColumn = getResizingColumn(header, e.getPoint());
if (tableColumn == null) return;
int col = header.getColumnModel().getColumnIndex(tableColumn.getIdentifier());
JTable table = header.getTable();
int rowCount = table.getRowCount();
int width = (int) header.getDefaultRenderer().getTableCellRendererComponent(table, tableColumn.getIdentifier(), false, false, -1, col).getPreferredSize().getWidth();
for (int row = 0; row < rowCount; row++) {
int preferedWidth = (int) table.getCellRenderer(row, col).getTableCellRendererComponent(table, table.getValueAt(row, col), false, false, row, col).getPreferredSize().getWidth();
width = Math.max(width, preferedWidth);
}
header.setResizingColumn(tableColumn); /* this line is very important */
tableColumn.setWidth(width + table.getIntercellSpacing().width);
}
}
代码示例来源:origin: girtel/Net2Plan
/**
* @return THe table column and true if of fixed, false if scrollable. Null if not visible now
*/
private Pair<TableColumn,Boolean> getTableColumnObject (AjtColumnInfo col)
{
try { final int indexInFixed = getFixedLeftTableColumnModel().getColumnIndex(col.getHeader()); return Pair.of(getFixedLeftTableColumnModel().getColumn(indexInFixed) , true); } catch (Exception e) { }
try { final int indexInScrollable = getScrollableRightTableColumnModel().getColumnIndex(col.getHeader()); return Pair.of(getScrollableRightTableColumnModel().getColumn(indexInScrollable),false); } catch (Exception e) { }
return Pair.of((TableColumn) null, (Boolean) null);
}
代码示例来源:origin: org.apache.cayenne.modeler/cayenne-modeler
private void updateOrder() {
TableColumn column;
TableColumnModel columnModel = table.getColumnModel();
TableModel model = table.getModel();
String columnName = "";
for (int i = 0; i < columnCount; i++) {
columnName = model.getColumnName(i);
column = table.getColumn(columnName);
int modelIndex = column.getModelIndex();
int orderIndex = getOrderIndex(modelIndex, modelIndex);
if (i != orderIndex) {
table.moveColumn(columnModel.getColumnIndex(columnName), orderIndex);
}
}
}
代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-common
public void mouseClicked(final MouseEvent _e){
if(_e.getClickCount()!=2) {
return;
}
final JTableHeader header = (JTableHeader)_e.getSource();
final TableColumn tableColumn = getResizingColumn(header, _e.getPoint());
if(tableColumn==null) {
return;
}
final int col = header.getColumnModel().getColumnIndex(tableColumn.getIdentifier());
final JTable table = header.getTable();
final int rowCount = table.getRowCount();
int width = (int)header.getDefaultRenderer()
.getTableCellRendererComponent(table, tableColumn.getIdentifier()
, false, false, -1, col).getPreferredSize().getWidth();
for(int row = 0; row<rowCount; row++){
final int preferedWidth = (int)table.getCellRenderer(row, col).getTableCellRendererComponent(table,
table.getValueAt(row, col), false, false, row, col).getPreferredSize().getWidth();
width = Math.max(width, preferedWidth);
}
header.setResizingColumn(tableColumn); // this line is very important
tableColumn.setWidth(width+table.getIntercellSpacing().width);
}
代码示例来源:origin: org.zaproxy/zap
private void showPopup(int index) {
Object headerValue = columnModel.getColumn(index).getHeaderValue();
int columnCount = columnModel.getColumnCount();
JPopupMenu popup = new SelectPopupMenu();
// Create a menu item for all columns managed by the table column
// manager, checking to see if the column is shown or hidden.
for (TableColumn tableColumn : allColumns) {
Object value = tableColumn.getHeaderValue();
JCheckBoxMenuItem item = new JCheckBoxMenuItem(value.toString());
item.addActionListener(this);
try {
columnModel.getColumnIndex(value);
item.setSelected(true);
if (columnCount == 1) {
item.setEnabled(false);
}
} catch (IllegalArgumentException e) {
item.setSelected(false);
}
popup.add(item);
if (value == headerValue) {
popup.setSelected(item);
}
}
// Display the popup below the TableHeader
JTableHeader header = table.getTableHeader();
Rectangle r = header.getHeaderRect(index);
popup.show(header, r.x, r.height);
}
代码示例来源:origin: org.zaproxy/zap
/**
* Show a hidden column in the table. The column will be positioned at its
* proper place in the view of the table.
*
* @param column
* the TableColumn to be shown.
*/
private void showColumn(TableColumn column) {
// Ignore changes to the TableColumnModel made by the TableColumnManager
columnModel.removeColumnModelListener(this);
// Add the column to the end of the table
columnModel.addColumn(column);
// Move the column to its position before it was hidden.
// (Multiple columns may be hidden so we need to find the first
// visible column before this column so the column can be moved
// to the appropriate position)
int position = allColumns.indexOf(column);
int from = columnModel.getColumnCount() - 1;
int to = 0;
for (int i = position - 1; i > -1; i--) {
try {
TableColumn visibleColumn = allColumns.get(i);
to = columnModel.getColumnIndex(visibleColumn.getHeaderValue()) + 1;
break;
} catch (IllegalArgumentException e) {
}
}
columnModel.moveColumn(from, to);
columnModel.addColumnModelListener(this);
}
代码示例来源:origin: com.jtattoo/JTattoo
public void mouseDragged(MouseEvent e) {
if ((header == null) || (header.getTable() == null)) {
return;
}
boolean rolloverEnabled = Boolean.TRUE.equals(header.getClientProperty("rolloverEnabled"));
boolean sortingAllowed = false;
if (JTattooUtilities.getJavaVersion() >= 1.6) {
sortingAllowed = header.getTable().getRowSorter() != null;
}
if (rolloverEnabled || sortingAllowed || header.getReorderingAllowed()) {
if (header.getDraggedColumn() != null && header.getDraggedColumn().getIdentifier() != null) {
rolloverCol = header.getColumnModel().getColumnIndex(header.getDraggedColumn().getIdentifier());
} else if (header.getResizingColumn() != null) {
rolloverCol = -1;
}
}
}
};
内容来源于网络,如有侵权,请联系作者删除!