本文整理汇总了Java中javax.swing.table.TableModel.getColumnCount方法的典型用法代码示例。如果您正苦于以下问题:Java TableModel.getColumnCount方法的具体用法?Java TableModel.getColumnCount怎么用?Java TableModel.getColumnCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.table.TableModel
的用法示例。
在下文中一共展示了TableModel.getColumnCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import javax.swing.table.TableModel; //导入方法依赖的package包/类
private void validate(int viewRow, int viewCol) {
JTable table = (JTable) getComponent();
try {
int row = table.convertRowIndexToModel(viewRow);
int col = table.convertColumnIndexToModel(viewCol);
TableModel model = table.getModel();
if (row >= 0 && row < model.getRowCount() && col >= 0 && col < model.getColumnCount()) {
if (table.isCellEditable(viewRow, viewCol)) {
return;
} else {
throw new NoSuchElementException("The cell is not editable on JTable: (" + viewRow + ", " + viewCol + ")",
null);
}
}
} catch (IndexOutOfBoundsException e) {
}
throw new NoSuchElementException("Invalid row/col for JTable: (" + viewRow + ", " + viewCol + ")", null);
}
示例2: createDefaultColumnsFromModel
import javax.swing.table.TableModel; //导入方法依赖的package包/类
@Override
public void createDefaultColumnsFromModel() {
TableModel m = getModel();
if( m != null ) {
// Remove any current columns
TableColumnModel cm = getColumnModel();
while( cm.getColumnCount() > 0 ) {
cm.removeColumn( cm.getColumn(0) );
}
// Create new columns from the data model info
for( int i=0; i<m.getColumnCount(); i++ ) {
TableColumn newColumn = new MyTableColumn(i);
if( i == TaskListModel.COL_LOCATION )
newColumn.setCellRenderer( new LeftDotRenderer() );
else if( i != TaskListModel.COL_GROUP )
newColumn.setCellRenderer( new TooltipRenderer() );
addColumn(newColumn);
}
}
}
示例3: checkModelFromComponent
import javax.swing.table.TableModel; //导入方法依赖的package包/类
/**
* Called when model from existing component is selected
* to update columns tab.
*/
private void checkModelFromComponent() {
try {
Object value = modelFromComponentEd.getValue();
if (value instanceof FormDesignValue) {
value = ((FormDesignValue)value).getDesignValue();
}
if (value instanceof TableModel) {
TableModel model = (TableModel)value;
ensureColumnCount(model.getColumnCount());
for (int i=0; i<model.getColumnCount(); i++) {
FormProperty title = columns.get(i).getColumn().getTitle();
if (!title.isChanged()) {
title.setValue(model.getColumnName(i));
}
}
} else {
ensureColumnCount(0);
}
} catch (Exception ex) {
Logger.getLogger(getClass().getName()).log(Level.INFO, ex.getMessage(), ex);
}
}
示例4: saveProperties
import javax.swing.table.TableModel; //导入方法依赖的package包/类
private boolean saveProperties() {
final Map<String, Object> properties = new HashMap<String, Object>();
final TableModel model = table.getModel();
if (model.getColumnCount() == 2) {
for (int i = 0; i < model.getRowCount(); i++) {
final String key = (String) model.getValueAt(i, 0);
final Object value = model.getValueAt(i, 1);
if (properties.containsKey(key)) {
return false;
} else {
properties.put(key, value);
}
}
sourceFile.setProperties(properties);
return true;
} else {
return false;
}
}
示例5: saveProperties
import javax.swing.table.TableModel; //导入方法依赖的package包/类
private boolean saveProperties() {
final Map<String, Object> properties = new HashMap<String, Object>();
final TableModel model = table.getModel();
if (model.getColumnCount() == 2) {
for (int i = 0; i < model.getRowCount(); i++) {
final String key = (String) model.getValueAt(i, 0);
final Object value = model.getValueAt(i, 1);
if (properties.containsKey(key)) {
return false;
} else {
properties.put(key, value);
}
}
node.getGraphNode().setProperties(properties);
return true;
} else {
return false;
}
}
示例6: tableChanged
import javax.swing.table.TableModel; //导入方法依赖的package包/类
/***
* 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);
}
示例7: writeData
import javax.swing.table.TableModel; //导入方法依赖的package包/类
protected void writeData(TableModel model, String title, Writer writer,
TracerProgressObject progress) throws IOException {
int columnsCount = model.getColumnCount();
int rowsCount = model.getRowCount();
for (int c = 0; c < columnsCount; c++) {
write(writer, "\"" + model.getColumnName(c) + "\""); // NOI18N
if (c < columnsCount - 1) write(writer, DELIMITER);
}
writeLine(writer);
for (int r = 0; r < rowsCount; r++) {
for (int c = 0; c < columnsCount; c++) {
write(writer, "\"" + model.getValueAt(r, c) + "\""); // NOI18N
if (c < columnsCount - 1) write(writer, DELIMITER);
}
writeLine(writer);
if (progress.isFinished()) break;
if (step == 1) {
progress.addStep();
} else {
int currentStep = (int)(r * step);
if (currentStep > lastStep) {
progress.addStep();
lastStep = currentStep;
}
}
}
}
示例8: writeData
import javax.swing.table.TableModel; //导入方法依赖的package包/类
protected void writeData(TableModel model, String title, Writer writer,
TracerProgressObject progress) throws IOException {
int columnsCount = model.getColumnCount();
int rowsCount = model.getRowCount();
writeLine(writer, " <TableData NumRows=\"" + rowsCount + // NOI18N
"\" NumColumns=\"" + columnsCount + "\">"); // NOI18N
writeLine(writer, " <TableHeader>"); // NOI18N
for (int c = 0; c < columnsCount; c++)
writeLine(writer, " <TableColumn>" + model.getColumnName(c) + "</TableColumn>"); // NOI18N
writeLine(writer, " </TableHeader>"); // NOI18N
writeLine(writer, " <TableBody>"); // NOI18N
for (int r = 0; r < rowsCount; r++) {
writeLine(writer, " <TableRow>"); // NOI18N
for (int c = 0; c < columnsCount; c++)
writeLine(writer, " <TableColumn>" + model.getValueAt(r, c) + "</TableColumn>"); // NOI18N
writeLine(writer, " </TableRow>"); // NOI18N
if (progress.isFinished()) break;
if (step == 1) {
progress.addStep();
} else {
int currentStep = (int)(r * step);
if (currentStep > lastStep) {
progress.addStep();
lastStep = currentStep;
}
}
}
writeLine(writer, " </TableBody>"); // NOI18N
writeLine(writer, " </TableData>"); // NOI18N
}
示例9: writeData
import javax.swing.table.TableModel; //导入方法依赖的package包/类
protected void writeData(TableModel model, String title, Writer writer,
TracerProgressObject progress) throws IOException {
int columnsCount = model.getColumnCount();
int rowsCount = model.getRowCount();
writeLine(writer, " <table border=\"1\" summary=\"" + title + "\">"); // NOI18N
writeLine(writer, " <thead>"); // NOI18N
writeLine(writer, " <tr>"); // NOI18N
for (int c = 0; c < columnsCount; c++)
writeLine(writer, " <td>" + model.getColumnName(c) + "</td>"); // NOI18N
writeLine(writer, " </tr>"); // NOI18N
writeLine(writer, " </thead>"); // NOI18N
writeLine(writer, " <tbody>"); // NOI18N
for (int r = 0; r < rowsCount; r++) {
writeLine(writer, " <tr>"); // NOI18N
for (int c = 0; c < columnsCount; c++)
writeLine(writer, " <td>" + model.getValueAt(r, c) + "</td>"); // NOI18N
writeLine(writer, " </tr>"); // NOI18N
if (progress.isFinished()) break;
if (step == 1) {
progress.addStep();
} else {
int currentStep = (int)(r * step);
if (currentStep > lastStep) {
progress.addStep();
lastStep = currentStep;
}
}
}
writeLine(writer, " </tbody>"); // NOI18N
writeLine(writer, " </table>"); // NOI18N
}
示例10: DataTable
import javax.swing.table.TableModel; //导入方法依赖的package包/类
public DataTable(TableModel model) {
super(model);
setSurrendersFocusOnKeystroke(true);
TableColumnModel cmodel = getColumnModel();
int i;
int ccount = model.getColumnCount();
int columnWidth;
int preferredWidth;
String columnName;
int width = 0;
for (i = 0; i < ccount; i++) {
TableColumn col = cmodel.getColumn(i);
Map cmap = ColumnItem.getColumnProperty(i);
col.setIdentifier(cmap.get("name")); //NOI18N
columnName = NbBundle.getMessage (CreateTableDialog.class, "CreateTable_" + i); //NOI18N
columnWidth = (new Double(getFontMetrics(getFont()).getStringBounds(columnName, getGraphics()).getWidth())).intValue() + 20;
if (cmap.containsKey("width")) { // NOI18N
if (((Integer)cmap.get("width")).intValue() < columnWidth)
col.setPreferredWidth(columnWidth);
else
col.setPreferredWidth(((Integer)cmap.get("width")).intValue()); // NOI18N
preferredWidth = col.getPreferredWidth();
}
if (cmap.containsKey("minwidth")) // NOI18N
if (((Integer)cmap.get("minwidth")).intValue() < columnWidth)
col.setMinWidth(columnWidth);
else
col.setMinWidth(((Integer)cmap.get("minwidth")).intValue()); // NOI18N
// if (cmap.containsKey("alignment")) {}
// if (cmap.containsKey("tip")) ((JComponent)col.getCellRenderer()).setToolTipText((String)cmap.get("tip"));
if (i < 7) { // the first 7 columns should be visible
width += col.getPreferredWidth();
}
}
width = Math.min(Math.max(width, 380), Toolkit.getDefaultToolkit().getScreenSize().width - 100);
setPreferredScrollableViewportSize(new Dimension(width, 150));
}
示例11: createDefaultColumnsFromModel
import javax.swing.table.TableModel; //导入方法依赖的package包/类
public void createDefaultColumnsFromModel() {
TableModel m = getModel();
if (m != null) {
// Remove any current columns
ProfilerColumnModel cm = _getColumnModel();
while (cm.getColumnCount() > 0)
cm.removeColumn(cm.getColumn(0));
// Create new columns from the data model info
for (int i = 0; i < m.getColumnCount(); i++)
addColumn(cm.createTableColumn(i));
}
}
示例12: setModel
import javax.swing.table.TableModel; //导入方法依赖的package包/类
@Override
public void setModel(TableModel dataModel) {
super.setModel(dataModel);
if (dataModel.getColumnCount() < 7) {
setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
} else {
setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
}
}
示例13: setModel
import javax.swing.table.TableModel; //导入方法依赖的package包/类
@Override
public void setModel(final TableModel model) {
boolean shouldSort = this.sortable && checkIfSortable(model);
if (shouldSort) {
this.tableSorter = new ExtendedJTableSorterModel(model);
this.tableSorter.setTableHeader(getTableHeader());
super.setModel(this.tableSorter);
} else {
super.setModel(model);
this.tableSorter = null;
}
originalOrder = new String[model.getColumnCount()];
for (int c = 0; c < model.getColumnCount(); c++) {
originalOrder[c] = model.getColumnName(c);
}
// initializing arrays for cell renderer settings
cutOnLineBreaks = new boolean[model.getColumnCount()];
maximalTextLengths = new int[model.getColumnCount()];
Arrays.fill(maximalTextLengths, Integer.MAX_VALUE);
model.addTableModelListener(new TableModelListener() {
@Override
public void tableChanged(final TableModelEvent e) {
int oldLength = cutOnLineBreaks.length;
if (oldLength != model.getColumnCount()) {
cutOnLineBreaks = Arrays.copyOf(cutOnLineBreaks, model.getColumnCount());
maximalTextLengths = Arrays.copyOf(maximalTextLengths, model.getColumnCount());
if (oldLength < cutOnLineBreaks.length) {
Arrays.fill(cutOnLineBreaks, oldLength, cutOnLineBreaks.length, false);
Arrays.fill(maximalTextLengths, oldLength, cutOnLineBreaks.length, Integer.MAX_VALUE);
}
}
}
});
}
示例14: validateRowCol
import javax.swing.table.TableModel; //导入方法依赖的package包/类
private void validateRowCol() {
JTable table = (JTable) parent.getComponent();
try {
int row = table.convertRowIndexToModel(viewRow);
int col = table.convertColumnIndexToModel(viewCol);
TableModel model = table.getModel();
if (row >= 0 && row < model.getRowCount() && col >= 0 && col < model.getColumnCount()) {
return;
}
} catch (IndexOutOfBoundsException e) {
}
throw new NoSuchElementException("Invalid row/col for JTable: (" + viewRow + ", " + viewCol + ")", null);
}
示例15: TableModelComparator
import javax.swing.table.TableModel; //导入方法依赖的package包/类
public TableModelComparator(TableModel model) {
this.model = model;
// XXX - Should actually listen for column changes and resize
columns = new int[model.getColumnCount()];
columns[0] = -1;
}