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


Java JTable.changeSelection方法代码示例

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


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

示例1: 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

示例2: 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

示例3: createMapping

import javax.swing.JTable; //导入方法依赖的package包/类
private JComponent createMapping()
{
	attributeModel = new AttributeTableModel();
	attributeTable = new JTable(attributeModel);

	attributeTable.setModel(attributeModel);
	attributeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	attributeTable.changeSelection(0, 0, false, true);

	return new JScrollPane(attributeTable);
}
 
开发者ID:equella,项目名称:Equella,代码行数:12,代码来源:LDAPMappingPanel.java

示例4: 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

示例5: tableChanged

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

	JTable tmp = this.voiceTab.getCmdsHistoryTable();
	tmp.changeSelection(tmp.getRowCount() - 1, 0, false, false);
	
	
}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:10,代码来源:VoicePanel.java


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