本文整理汇总了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);
}
}
示例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);
}
}
}
}
示例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);
}
示例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);
}
}
示例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);
}