本文整理汇总了Java中javax.swing.JTable.getSelectedRow方法的典型用法代码示例。如果您正苦于以下问题:Java JTable.getSelectedRow方法的具体用法?Java JTable.getSelectedRow怎么用?Java JTable.getSelectedRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTable
的用法示例。
在下文中一共展示了JTable.getSelectedRow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import javax.swing.JTable; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent ae) {
JTable jt = (JTable) ae.getSource();
int row = jt.getSelectedRow();
int col = jt.getSelectedColumn();
if ((row != -1) && (col != -1)) {
if (PropUtils.isLoggable(BaseTable.class)) {
PropUtils.log(BaseTable.class, "Starting edit due to key event for row " + row); //NOI18N
}
jt.editCellAt(row, 1, null);
//Focus will be rerouted to the editor via this call:
jt.requestFocus();
}
}
示例2: rightClick
import javax.swing.JTable; //导入方法依赖的package包/类
public void rightClick(JTable jtable, java.awt.event.MouseEvent evt ){
try {
impostaMenu();
} catch (SQLException ex) {
Logger.getLogger(GuiPrincipale.class.getName()).log(Level.SEVERE, null, ex);
}
if(SwingUtilities.isRightMouseButton(evt)){
int[] coordinate = coordinateMouse(jtable);
jMenuPrincipale.show(this, coordinate[0]+evt.getX(), coordinate[1]+evt.getY());
}
try{
int i = jtable.getSelectedRow();
id = Integer.parseInt(jtable.getValueAt(i, 2).toString());
nomePrenotazione = (String) jtable.getValueAt(i, 0);
}catch(ArrayIndexOutOfBoundsException s){}
}
示例3: RTable
import javax.swing.JTable; //导入方法依赖的package包/类
public RTable(Component source, JSONOMapConfig omapConfig, Point point, IJSONRecorder recorder) {
super(source, omapConfig, point, recorder);
JTable table = (JTable) source;
if (table.isEditing()) {
column = table.getEditingColumn();
row = table.getEditingRow();
} else {
if (point != null) {
row = table.rowAtPoint(point);
column = table.columnAtPoint(point);
} else {
row = table.getSelectedRow();
column = table.getSelectedColumn();
}
}
if (row == -1 || column == -1) {
row = column = -1;
}
}
示例4: getEncryptAction
import javax.swing.JTable; //导入方法依赖的package包/类
private static AbstractAction getEncryptAction(final JTable table) {
return new AbstractAction() {
@Override
public void actionPerformed(ActionEvent me) {
try {
int col = table.getSelectedColumn();
int row = table.getSelectedRow();
if (col > -1 && row > -1) {
String data = table.getValueAt(row, col).toString();
table.setValueAt(TMIntegration.encrypt(data), row, col);
}
} catch (HeadlessException ex) {
Logger.getLogger(TMSettingsControl.class.getName())
.log(Level.SEVERE, ex.getMessage(), ex);
}
}
};
}
示例5: moverowdown
import javax.swing.JTable; //导入方法依赖的package包/类
/**
* Moves the selected nullRoww one nullRoww DOWN., unless it is the last
* nullRoww
*
* @param table the target tmodel
*/
public static void moverowdown(JTable table) {
int sRow = table.getSelectedRow();
if (sRow < table.getRowCount() - 1 && sRow >= 0) {
((DefaultTableModel) table.getModel()).moveRow(sRow, sRow, sRow + 1);
table.getSelectionModel().setSelectionInterval(sRow + 1, sRow + 1);
}
}
示例6: 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);
}
示例7: 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);
}
}
示例8: 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);
}
}
}
}
示例9: updateCellRangeByTableSelection
import javax.swing.JTable; //导入方法依赖的package包/类
/**
* Uses the current table selection to update the cell range selection.
*/
void updateCellRangeByTableSelection(JTable contentTable) {
int columnIndexStart = contentTable.getSelectedColumn();
int rowIndexStart = contentTable.getSelectedRow();
int columnIndexEnd = columnIndexStart + contentTable.getSelectedColumnCount() - 1;
int rowIndexEnd = rowIndexStart + contentTable.getSelectedRowCount() - 1;
setCellRangeSelection(new CellRangeSelection(columnIndexStart, rowIndexStart, columnIndexEnd, rowIndexEnd));
}
示例10: right
import javax.swing.JTable; //导入方法依赖的package包/类
public void right()
{
TreePath path = directory.getSelectionPath();
if( path == null )
{
return;
}
TreeNode2 tmp = (TreeNode2) path.getLastPathComponent();
JTable table = getSelectedTable();
int row = table.getSelectedRow();
table.getModel().setValueAt(tmp.toString(), row, 1);
table.updateUI();
}
示例11: actionPerformed
import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e)
{
if( e.getSource() == left )
{
JTable table = getSelectedTable();
int row = table.getSelectedRow();
attributeModel.setValueAt("", row, 1);
table.updateUI();
}
else if( e.getSource() == right )
{
right();
}
}
示例12: moverowup
import javax.swing.JTable; //导入方法依赖的package包/类
/**
* Moves the selected nullRoww one nullRoww UP., unless it the first
* nullRoww
*
* @param table the target tmodel
*/
public static void moverowup(JTable table) {
int sRow = table.getSelectedRow();
if (sRow > 0) {
((DefaultTableModel) table.getModel()).moveRow(sRow, sRow, sRow - 1);
table.getSelectionModel().setSelectionInterval(sRow - 1, sRow - 1);
}
}
示例13: deleterow
import javax.swing.JTable; //导入方法依赖的package包/类
/**
* get all selected rows and DELETE one by one from the last.
*
* @param table the table to DELETE rows
*/
public static void deleterow(JTable table) {
int[] selectedrows = table.getSelectedRows();
for (int row : selectedrows) {
row = table.getSelectedRow();
if (table.getRowSorter() != null) {
row = table.getRowSorter().convertRowIndexToModel(row);
}
((DefaultTableModel) table.getModel()).removeRow(row);
}
}
示例14: addrow
import javax.swing.JTable; //导入方法依赖的package包/类
/**
* Inserts new row if any row is selected else adds new row at the end
*
* @param table
*/
public static void addrow(JTable table) {
int rowindex = table.getRowCount();
if (table.getSelectedRow() > -1) {
((DefaultTableModel) table.getModel()).addRow(nullRow);
((DefaultTableModel) table.getModel()).moveRow(table.getRowCount() - 1, table.getRowCount() - 1, table.getSelectedRow());
rowindex = table.getSelectedRow();
} else {
((DefaultTableModel) table.getModel()).addRow(nullRow);
}
table.scrollRectToVisible(new Rectangle(table.getCellRect(rowindex, 0, true)));
}
示例15: mousePressed
import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public void mousePressed(MouseEvent e) {
Object s = e.getSource();
if (s instanceof JTable) {
JTable t = (JTable) s;
int x = t.getSelectedRow();
int y = t.getSelectedColumn();
if (x != -1 && y != -1) {
Object d = Objects.toString(t.getModel().getValueAt(x, y), "");
startLocation = new Cell(x, y, d);
}
}
}