当前位置: 首页>>代码示例>>Java>>正文


Java JTable.convertRowIndexToModel方法代码示例

本文整理汇总了Java中javax.swing.JTable.convertRowIndexToModel方法的典型用法代码示例。如果您正苦于以下问题:Java JTable.convertRowIndexToModel方法的具体用法?Java JTable.convertRowIndexToModel怎么用?Java JTable.convertRowIndexToModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JTable的用法示例。


在下文中一共展示了JTable.convertRowIndexToModel方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validate

import javax.swing.JTable; //导入方法依赖的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);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:19,代码来源:JTableJavaElement.java

示例2: getNextNode

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public T getNextNode (T node) {
    T next = null;
    if (node != null) {
        int index = Arrays.asList(tableModel.getNodes()).indexOf(node);
        if (index >= 0) {
            JTable table = getTable();
            index = table.convertRowIndexToView(index);
            if (++index < table.getRowCount()) {
                next = tableModel.getNodes()[table.convertRowIndexToModel(index)];
            }
        }
    }
    return next;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:VCSStatusTable.java

示例3: getPreviousNode

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public T getPreviousNode (T node) {
    T prev = null;
    if (node != null) {
        int index = Arrays.asList(tableModel.getNodes()).indexOf(node);
        if (index >= 0) {
            JTable table = getTable();
            index = table.convertRowIndexToView(index);
            if (--index >= 0) {
                prev = tableModel.getNodes()[table.convertRowIndexToModel(index)];
            }
        }
    }
    return prev;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:VCSStatusTable.java

示例4: getTableCellEditorComponent

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, final int row, final int column) {
    final JComponent c = (JComponent) super.getTableCellEditorComponent(table, value, isSelected, row, column);      
    
    this.tableModel = table.getModel();
    this.columnName = table.getColumnName(column);
    this.modelRow = table.convertRowIndexToModel(row);
    this.modelColumn = table.convertColumnIndexToModel(column);  
    this.tc = c instanceof JTextComponent ? (JTextComponent) c : null;

    JPanel panel = new JPanel(new BorderLayout()) {
        @Override
        public void addNotify() {
            super.addNotify();
            c.requestFocus();
        }
    };
    panel.add(c);
    if (suppressEditorBorder) {
        c.setBorder(BorderFactory.createEmptyBorder());
    }
    panel.add(customEditorButton, BorderLayout.EAST);
    panel.revalidate();
    panel.repaint();

    return panel;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:StringTableCellEditor.java

示例5: addEmptyRow

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public void addEmptyRow(JTable jTable){
	
	// --- Get current position in the table model ----
	Vector<Number> rowSelected = null;
	Vector<Number> newRow = null;
	long currKey = 0L;
	long newKey = 0L;
	float newValue = 0f;
	
	// --- Get the current or the last row ------------
	int modelLineSelected = 0;
	int modelLineSelectedNew = 0;
	int tableRowSelected = 0;
	int tableRowSelectedNew = 0;
		
	tableRowSelected = jTable.getSelectedRow();
	if (tableRowSelected==-1 || tableRowSelected>=jTable.getRowCount()) {
		tableRowSelected = jTable.getRowCount()-1;
	}
	
	if (tableModelDataVector.size()==0) {
		// --- Create new data series -------
		DataSeries newSeries = parentDataModel.createNewDataSeries(parentDataModel.getDefaultSeriesLabel());
		
		ValuePair initialValuePair = parentDataModel.createNewValuePair(0L, newValue);
		parentDataModel.getValuePairsFromSeries(newSeries).add(initialValuePair);
		parentDataModel.addSeries(newSeries);
		
	} else {
		// --- Get current selection --------
		modelLineSelected = jTable.convertRowIndexToModel(tableRowSelected);
		rowSelected = tableModelDataVector.get(modelLineSelected);
		currKey = (Long) rowSelected.get(tableModelDataVector.getKeyColumnIndex());
		
		// --- Find a new key value ---------
		newKey = currKey + 1L;
		while (tableModelDataVector.getKeyRowVectorTreeMap().get(newKey)!=null) {
			newKey = newKey + 1L;
		}
		
		// --- Find new index position ------
		modelLineSelectedNew = tableModelDataVector.size();
		for (int i=0; i < tableModelDataVector.size(); i++) {
			Vector<Number> row = tableModelDataVector.get(i);
			long key = (Long) row.get(0);
			if (key>newKey) {
				modelLineSelectedNew = i;
				break;
			}
		}
		
		// --- Add new row data -------------
		newRow = new Vector<Number>();
		newRow.add(newKey);
		for(int i=1; i<getColumnCount(); i++){
			newRow.add(newValue);
			try {
				this.getChartModel().addOrUpdateValuePair(i-1, newKey, newValue);
				this.getOntologyModel().addOrUpdateValuePair(i-1, newKey, newValue);
				
			} catch (NoSuchSeriesException e) {
				e.printStackTrace();
			}
		}
		// --- Add new row to table model ---
		tableModelDataVector.add(modelLineSelectedNew, newRow);
		
	}
	fireTableRowsInserted(0, getRowCount()-1);
	
	// --- Set new selection ----------------
	tableRowSelectedNew = jTable.convertRowIndexToView(modelLineSelectedNew);
	if(tableRowSelectedNew >= 0){
		jTable.setRowSelectionInterval(tableRowSelectedNew, tableRowSelectedNew);
		jTable.changeSelection(tableRowSelectedNew, 0, false, false);
	}
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:79,代码来源:TimeSeriesTableModel.java

示例6: move

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * Moves the current selection according to the direction.
 * @param direction the direction to move
 */
public void move(JTable jTable, int direction) {
	
	if (jTable.getSelectedRow()!=-1 && direction!=0) {
		
		int selectedRowTableNew; 
		int selectedRowModelNew;
		int selectedRowTable = jTable.getSelectedRow();
		int selectedRowModel = jTable.convertRowIndexToModel(selectedRowTable);
		
		if (!((selectedRowModel==0 && direction<0) || (selectedRowModel==this.tableModelDataVector.size()-1 && direction>0))) {
			Vector<Number> rowSelected = this.tableModelDataVector.remove(selectedRowModel);
			XyValuePair xyValuePair = (XyValuePair) this.getOntologyModel().removeXyValuePair(this.getFocusedSeriesIndex(), selectedRowModel);
			
			if (direction>0) {
				// --- move down ------------
				selectedRowModelNew = selectedRowTable+1; 
				this.tableModelDataVector.add(selectedRowModelNew, rowSelected);
				this.getOntologyModel().addXyValuePair(this.getFocusedSeriesIndex(), selectedRowModelNew, xyValuePair);
				this.getChartModel().setXYSeriesAccordingToOntologyModel(this.getFocusedSeriesIndex());
				fireTableRowsInserted(selectedRowModel, selectedRowModelNew);
				
			} else {
				// --- move up --------------
				selectedRowModelNew = selectedRowTable-1; 
				this.tableModelDataVector.add(selectedRowModelNew, rowSelected);
				this.getOntologyModel().addXyValuePair(this.getFocusedSeriesIndex(), selectedRowModelNew, xyValuePair);
				this.getChartModel().setXYSeriesAccordingToOntologyModel(this.getFocusedSeriesIndex());
				fireTableRowsInserted(selectedRowModelNew, selectedRowModel);
			}
			
			selectedRowTableNew = jTable.convertRowIndexToView(selectedRowModelNew);
			if(selectedRowTableNew >= 0){
				jTable.setRowSelectionInterval(selectedRowTableNew, selectedRowTableNew);
				jTable.changeSelection(selectedRowTableNew, 0, false, false);
			}
		}
	}
	
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:44,代码来源:XyTableModel.java

示例7: getTableCellRendererComponent

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
	
	this.dynTable = (DynTable) table;
	this.dynType  = (DynType) value;
	this.isSelected = isSelected;
	this.rowTable = row;
	this.rowModel = table.convertRowIndexToModel(row);

	if (column==0) {
		return this.getFirstColumnDisplay();
	} else {
		return this.getSecondColumnDisplayAndEditPanel();	
	}
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:16,代码来源:DynTableCellRenderEditor.java

示例8: getTableCellEditorComponent

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
	
	this.dynTable = (DynTable) table;
	this.dynType  = (DynType) value;
	this.isSelected = isSelected;
	this.rowTable = row;
	this.rowModel = table.convertRowIndexToModel(row);
	
	return this.getSecondColumnDisplayAndEditPanel();	
	
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:13,代码来源:DynTableCellRenderEditor.java

示例9: validateRowCol

import javax.swing.JTable; //导入方法依赖的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);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:14,代码来源:JTableCellJavaElement.java

示例10: removeRow

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public void removeRow(JTable jTable){

	int colIndexTable = jTable.getSelectedColumn();
	int rowIndexTable = jTable.getSelectedRow();
	
	int rowIndexModel = 0;
	int rowIndexTableNew = 0;
	int rowIndexModelNew = 0;
	
	// --- Stop editing -----------------
	if(jTable.isEditing()){
		jTable.getCellEditor().cancelCellEditing();
	}
	
	// ---- Last row of data series? ----
	if(jTable.getRowCount()==1){
		while(parentDataModel.getSeriesCount()>0){
			try {
				parentDataModel.removeSeries(0);
			} catch (NoSuchSeriesException e1) {
				// This cannot happen, as there where clause prevents empty models  
			}
		}
		rowIndexModelNew = -1;
		rowIndexTableNew = -1;
		
	}else{
		
		if ((rowIndexTable+1) > jTable.getRowCount()) {
			rowIndexTable = jTable.getRowCount() - 1;
		}
		Number key = (Number) jTable.getValueAt(rowIndexTable, 0);
		rowIndexModel = jTable.convertRowIndexToModel(rowIndexTable);
		((TimeSeriesDataModel)parentDataModel).removeValuePairsFromAllSeries(key);
		
		rowIndexModelNew = rowIndexModel;
		if (rowIndexModelNew>=jTable.getRowCount()) {
			rowIndexModelNew = jTable.getRowCount()-1;
		}
		rowIndexTableNew = jTable.convertRowIndexToView(rowIndexModelNew);
		
	}
	
	// --- Set new selection ------------
	if(rowIndexTableNew==-1){
		jTable.clearSelection();
	} else {
		jTable.setRowSelectionInterval(rowIndexTableNew, rowIndexTableNew);
		jTable.changeSelection(rowIndexTableNew, colIndexTable, false, false);
	}
	
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:54,代码来源:TimeSeriesTableModel.java


注:本文中的javax.swing.JTable.convertRowIndexToModel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。