本文整理汇总了Java中javax.swing.JTable.setRowSelectionInterval方法的典型用法代码示例。如果您正苦于以下问题:Java JTable.setRowSelectionInterval方法的具体用法?Java JTable.setRowSelectionInterval怎么用?Java JTable.setRowSelectionInterval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTable
的用法示例。
在下文中一共展示了JTable.setRowSelectionInterval方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: maybeShowPopup
import javax.swing.JTable; //导入方法依赖的package包/类
private void maybeShowPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
JTable source = (JTable)(e.getSource());
if ( ! source.isEnabled () ) return;
_inputTablePopupRow =
source.rowAtPoint(new Point (e.getX(), e.getY()));
_inputTablePopupColumn =
source.columnAtPoint(new Point (e.getX(), e.getY()));
// Make sure the row where click occurred is selected.
if (_inputTablePopupRow != -1) {
source.setRowSelectionInterval (_inputTablePopupRow,
_inputTablePopupRow);
}
// if ( _inputTablePopupColumn != Criteria_COLUMN )
// {
// // return without showing popup
// return;
// }
_inputTablePopup.show(e.getComponent(), e.getX(), e.getY());
}
}
示例2: setSelectedRow
import javax.swing.JTable; //导入方法依赖的package包/类
private void setSelectedRow(JTable table, Object selectedObject, int objectColumn) {
if(table==null || selectedObject==null || objectColumn==-1)return;
//after move to java6 as minimum requirent for nb may consider to replace with JTable::convertRowIndexToModel and back
//current mplementation works with java5
TableModel model = table.getModel();
int rowCount=table.getRowCount();
for(int i=0; i<rowCount; i++) {
if(selectedObject.equals(model.getValueAt(i, objectColumn))) {
table.setRowSelectionInterval(i, i);
table.scrollRectToVisible(table.getCellRect(i, objectColumn, true));
break;
}
}
}
示例3: maybeShowPopup
import javax.swing.JTable; //导入方法依赖的package包/类
private void maybeShowPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
JTable source = (JTable)(e.getSource());
int row = source.rowAtPoint(e.getPoint());
int column = source.columnAtPoint(e.getPoint());
// Make sure the row where click occurred is selected.
if (row != -1) {
source.setRowSelectionInterval (row, row);
}
resultTablePopup.show(e.getComponent(), e.getX(), e.getY());
}
}
示例4: keyPressed
import javax.swing.JTable; //导入方法依赖的package包/类
/** Handle the key pressed event and change the focus if a particular
* key combination is pressed. */
public void keyPressed(KeyEvent e) {
if( e.isShiftDown() ) {
int code = e.getKeyCode();
switch(code) {
// diagram pane
case KeyEvent.VK_F10:
JTable source = (JTable)(e.getSource());
if (DEBUG)
System.out.println( "QBIT : keyPressed called Shift+F10 Down source.isEnabled() returns : " + source.isEnabled() + "\n" );
if ( ! source.isEnabled () ) return;
// _inputTablePopupRow = source.getEditingRow();
_inputTablePopupRow = source.getSelectedRow();
_inputTablePopupColumn = source.getEditingColumn();
if (_inputTablePopupColumn == (Criteria_COLUMN-1)) {
source.setEditingColumn(Column_COLUMN);
}
if (DEBUG)
System.out.println( "QBIT : keyPressed called\n"
+ " inputTablePopupRow = " + _inputTablePopupRow // NOI18N
+ " inputTablePopupColumn == Criteria_COLUMN " + (_inputTablePopupRow == Criteria_COLUMN ) // NOI18N
+ " inputTablePopupColumn = " + _inputTablePopupColumn ); // NOI18N
// Make sure the row where click occurred is selected.
if (_inputTablePopupRow != -1) {
source.setRowSelectionInterval (_inputTablePopupRow,
_inputTablePopupRow);
}
_inputTablePopup.show ( source, source.getWidth() / 2,
source.getHeight() / 2 );
break;
}
}
_queryBuilder.handleKeyPress(e);
}
示例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);
}
}
示例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);
}
}
}
}
示例7: getClustDetTable
import javax.swing.JTable; //导入方法依赖的package包/类
private JTable getClustDetTable() {
tableClusters = new JTable(new clustDetModel(info.numElem, info.percent)) {
/**
*
*/
private static final long serialVersionUID = 1L;
{
setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
getColumnModel().getColumn(0).setPreferredWidth(170);
getColumnModel().getColumn(1).setPreferredWidth(110);
getColumnModel().getColumn(2).setPreferredWidth(110);
getColumnModel().getColumn(3).setPreferredWidth(55);
}
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
if (column == 3) {
return new ColorRenderer();
}
return getDefaultRenderer(String.class);
}
};
tableClusters.setSelectionBackground(new Color(83, 126, 126));
tableClusters.setSelectionForeground(Color.BLACK);
tableClusters.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
tableClusters.setFont(new Font(tableClusters.getFont().getName(), tableClusters.getFont().getStyle(), tableClusters.getFont().getSize() + 1));
tableClusters.setRowSelectionInterval(0, 0);
return tableClusters;
}
示例8: getVarsDetTable
import javax.swing.JTable; //导入方法依赖的package包/类
private JTable getVarsDetTable() {
double[] p = new double[numClust];
for (int i = 0; i < numClust; i++) {
p[i] = info.infoCluster[i].percVar[listVars.getSelectedIndex()];
}
tableVars = new JTable(new varsDetModel(p)) {
/**
*
*/
private static final long serialVersionUID = 1L;
{
setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
getColumnModel().getColumn(0).setPreferredWidth(170);
getColumnModel().getColumn(1).setPreferredWidth(100);
getColumnModel().getColumn(2).setPreferredWidth(55);
}
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
if (column == 2) {
return new ColorRenderer();
}
return getDefaultRenderer(String.class);
}
};
tableVars.setSelectionBackground(new Color(83, 126, 126));
tableVars.setSelectionForeground(Color.BLACK);
tableVars.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
tableVars.setFont(new Font(tableVars.getFont().getName(), tableVars.getFont().getStyle(), tableVars.getFont().getSize() + 1));
tableVars.setRowSelectionInterval(0, 0);
return tableVars;
}
示例9: 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);
}
}