我是靠谱客的博主 鲜艳电话,最近开发中收集的这篇文章主要介绍java getselectedrow_Java JTable.getSelectedRow方法代碼示例,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

本文整理匯總了Java中javax.swing.JTable.getSelectedRow方法的典型用法代碼示例。如果您正苦於以下問題:Java JTable.getSelectedRow方法的具體用法?Java JTable.getSelectedRow怎麽用?Java JTable.getSelectedRow使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JTable的用法示例。

在下文中一共展示了JTable.getSelectedRow方法的20個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: actionPerformed

​點讚 5

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();

}

}

開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,

示例2: RTable

​點讚 3

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;

}

}

開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:20,

示例3: rightClick

​點讚 3

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){}

}

開發者ID:IngSW-unipv,項目名稱:Progetto-N,代碼行數:19,

示例4: getEncryptAction

​點讚 3

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);

}

}

};

}

開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:20,

示例5: keyPressed

​點讚 2

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 calledn"

+ " 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);

}

開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:39,

示例6: addEmptyRow

​點讚 2

import javax.swing.JTable; //導入方法依賴的package包/類

@Override

public void addEmptyRow(JTable jTable){

// --- Get current position in the table model ----

Vector rowSelected = null;

Vector 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 row = tableModelDataVector.get(i);

long key = (Long) row.get(0);

if (key>newKey) {

modelLineSelectedNew = i;

break;

}

}

// --- Add new row data -------------

newRow = new Vector();

newRow.add(newKey);

for(int i=1; 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,

示例7: move

​點讚 2

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 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,

示例8: updateCellRangeByTableSelection

​點讚 2

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));

}

開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:11,

示例9: right

​點讚 2

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();

}

開發者ID:equella,項目名稱:Equella,代碼行數:16,

示例10: actionPerformed

​點讚 2

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();

}

}

開發者ID:equella,項目名稱:Equella,代碼行數:16,

示例11: moverowup

​點讚 2

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);

}

}

開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:15,

示例12: moverowdown

​點讚 2

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);

}

}

開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:14,

示例13: deleterow

​點讚 2

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);

}

}

開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:17,

示例14: addrow

​點讚 2

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)));

}

開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:17,

示例15: mousePressed

​點讚 2

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);

}

}

}

開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:14,

示例16: importData

​點讚 2

import javax.swing.JTable; //導入方法依賴的package包/類

@Override

public boolean importData(TransferHandler.TransferSupport support)

{

try

{

Run newdata[][] = (Run[][])support.getTransferable().getTransferData(flavor);

JTable target = (JTable)support.getComponent();

int dr,dc;

if (!support.isDrop())

{

/* Set the data */

dr = target.getSelectedRow();

dc = target.getSelectedColumn();

for (int ii = 0; ii < newdata.length; ii++)

for (int jj = 0; jj < newdata[0].length; jj++)

target.setValueAt((newdata[ii][jj]).clone(), dr+ii, dc+jj);

}

return true;

}

catch (UnsupportedFlavorException ufe) { log.warning("Sorry, you pasted data I don't work with"); }

catch (IOException ioe) { log.log(Level.WARNING, "I/O Error during paste:{0}", ioe.getMessage()); }

catch (Exception e) { log.log(Level.WARNING, "General error during paste:{0}", e.getMessage()); }

return false;

}

開發者ID:drytoastman,項目名稱:scorekeeperfrontend,代碼行數:29,

示例17: mouseClicked

​點讚 2

import javax.swing.JTable; //導入方法依賴的package包/類

@Override

public void mouseClicked(MouseEvent e) {

JTableHeader h = (JTableHeader) e.getSource();

JTable table = h.getTable();

int selectedRow = table.getSelectedRow();

TableModel model = table.getModel();

//remember selection to keep after sorting

Object selectedAction=null;

int objectColumn=-1;

if(selectedRow>-1) {

for(int i=0; i

//first find colum with appropriate object

if(model.getValueAt(selectedRow, i) instanceof ActionHolder) {

//remember this object

selectedAction=model.getValueAt(selectedRow, i);

objectColumn=i;

//stop edition as we click somewhere ouside of editor

TableCellEditor editor=table.getCellEditor();

if(editor!=null) {

editor.stopCellEditing();

}

break;

}

}

}

TableColumnModel columnModel = h.getColumnModel();

int viewColumn = columnModel.getColumnIndexAtX(e.getX());

int column = columnModel.getColumn(viewColumn).getModelIndex();

if (column != -1) {

int status = getSortingStatus(column);

if (!e.isControlDown()) {

cancelSorting();

}

// Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or

// {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.

status = status + (e.isShiftDown() ? -1 : 1);

status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}

setSortingStatus(column, status);

//reselect the same object

if(selectedAction!=null)setSelectedRow(table, selectedAction, objectColumn);

}

}

開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:43,

示例18: removeRow

​點讚 2

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,

示例19: addEmptyRowatEnd

​點讚 2

import javax.swing.JTable; //導入方法依賴的package包/類

/**

* if the selected row is last row then add an empty row at the end

*

* @param table the tmodel to add new empty row

*/

static void addEmptyRowatEnd(JTable table) {

if ((table.getRowCount() - 1) == table.getSelectedRow()) {

((DefaultTableModel) table.getModel()).addRow(nullRow);

}

}

開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:11,

示例20: datosFilaSeleccionada

​點讚 1

import javax.swing.JTable; //導入方法依賴的package包/類

public void datosFilaSeleccionada(JTable datostabla,DefaultTableModel modelo, String fecha, String apelDoctor)

//el "JTable" es para recibir la tabla ya con los datos

{

//Usando la variable que contiene LA TABLA CON LOS DATOS INTRODUCIDOS "datostabla"

int seleccion = datostabla.getSelectedRow(); //para saber si hay o no una seleccion en la tabla

String apelPaciente; //para guardar el codigo de la seleccion

int horaCita;//para guardar el nombre del curso de la seleccion

if(seleccion == -1)//si no se a seleccionado ninguna fila

//la variable "seleccion" varia en base a la fila seleccionada

//tomando cada fila con valores como un vector, iniciando desde "0"

{

JOptionPane.showMessageDialog(null, "ERROR: no se ha seleccionado ninguna fila para eliminar");

}

else

{

apelPaciente = (String) datostabla.getValueAt(seleccion, 1); //guardamos el apellido de la fila seleccionada

//en una variable string

horaCita = (int) datostabla.getValueAt(seleccion, 3); //guardamos la hora de la fila seleccionada

//en una variable string

//Usando la VARIABLE TIPO TABLA "modelo"

modelo.removeRow(seleccion); //utilizamos el modelo de la tabla para eliminar la fila SOLO VISUALMENTE

//------------------PARA REALIZAR LA ELIMINACION EN EL ARCHIVO-----------------------------------------------------------------------------------

EliminarCita(apelPaciente, apelDoctor, fecha, horaCita); //enviamos el modelo que recibimos y el codigo que ya sustraimos de la selecion

//------------------------------------------------------------------------------------------------------------------------------------------------

}

}

開發者ID:JuanJoseFJ,項目名稱:ProyectoPacientes,代碼行數:40,

注:本文中的javax.swing.JTable.getSelectedRow方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

最后

以上就是鲜艳电话为你收集整理的java getselectedrow_Java JTable.getSelectedRow方法代碼示例的全部内容,希望文章能够帮你解决java getselectedrow_Java JTable.getSelectedRow方法代碼示例所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(39)

评论列表共有 0 条评论

立即
投稿
返回
顶部