下面列出了javax.swing.JTable#setRowSelectionInterval ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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());
}
}
private static List<EquipNode> getMenuTargets(JTable table, MouseEvent e)
{
int row = table.rowAtPoint(e.getPoint());
if (!table.isRowSelected(row))
{
if ((row >= 0) && (table.getRowCount() > row))
{
table.setRowSelectionInterval(row, row);
}
}
return Arrays.stream(table.getSelectedRows())
.mapToObj(selRow -> table.getModel().getValueAt(selRow, 0))
.filter(value -> value instanceof EquipNode)
.map(value -> (EquipNode) value)
.collect(Collectors.toList());
}
private static List<EquipmentFacade> getMenuTargets(JTable table, MouseEvent e)
{
int row = table.rowAtPoint(e.getPoint());
if (!table.isRowSelected(row))
{
if ((row >= 0) && (table.getRowCount() > row))
{
table.setRowSelectionInterval(row, row);
}
}
return Arrays.stream(table.getSelectedRows())
.mapToObj(selRow -> table.getModel().getValueAt(selRow, 0))
.filter(value -> value instanceof EquipmentFacade)
.map(value -> (EquipmentFacade) value)
.collect(Collectors.toList());
}
private void showSelectedEntryDetails(JTable jtKeyStore, int row) {
jtKeyStore.setRowSelectionInterval(row, row);
updateCutCopyPasteControls(); // Selection changed - update edit controls
KeyStoreHistory history = getActiveKeyStoreHistory();
KeyStore keyStore = history.getCurrentState().getKeyStore();
String alias = getSelectedEntryAlias();
try {
if (KeyStoreUtil.isKeyPairEntry(alias, keyStore)) {
keyPairCertificateChainDetailsAction.showCertificateSelectedEntry();
} else if (KeyStoreUtil.isTrustedCertificateEntry(alias, keyStore)) {
trustedCertificateDetailsAction.showCertificateSelectedEntry();
} else if (KeyStoreUtil.isKeyEntry(alias, keyStore)) {
keyDetailsAction.showKeySelectedEntry();
}
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
@Override
protected void displayRow(JTable rtTable, int fromRow, int row) {
long reset_l = (long) rtTable.getValueAt(row, HealthTableModel.RESET_COL);
long uptime = (long)rtTable.getValueAt(row, HealthTableModel.UPTIME_COL);
//Log.println("RESET: " + reset);
//Log.println("UPTIME: " + uptime);
int reset = (int)reset_l;
maxPayload = Config.payloadStore.getFramePart(foxId, reset, uptime, Spacecraft.MAX_LAYOUT, true);
if (maxPayload != null)
updateTabMax(maxPayload);
minPayload = Config.payloadStore.getFramePart(foxId, reset, uptime, Spacecraft.MIN_LAYOUT, true);
if (minPayload != null)
updateTabMin(minPayload);
realTime = Config.payloadStore.getFramePart(foxId, reset, uptime, Spacecraft.REAL_TIME_LAYOUT, false);
if (realTime != null)
updateTabRT(realTime, false);
if (fromRow == NO_ROW_SELECTED)
fromRow = row;
if (fromRow <= row)
rtTable.setRowSelectionInterval(fromRow, row);
else
rtTable.setRowSelectionInterval(row, fromRow);
}
public static void shuffle() {
final JTable table = TabelPanel.table;
final int totalIndexs = table.getRowCount();
final int randomIndex = new Random().nextInt(totalIndexs);
table.setRowSelectionInterval(0, randomIndex);
MediaUtils.switchMedia(table);
}
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());
}
}
/** 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);
}
public static void repeat() {
final JTable table = TabelPanel.table;
if (table != null) {
if (table.getRowCount() > 0) {
final int index = table.getSelectedRow();
table.setRowSelectionInterval(0, index);
MediaUtils.switchMedia(table);
} else {
}
}
}
private void maybeShowPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
Component comp = e.getComponent();
if (comp instanceof JTable) {
JTable table = (JTable) comp;
int rowIndex = table.rowAtPoint(e.getPoint());
table.setRowSelectionInterval(rowIndex, rowIndex);
}
popupMenu.show(comp, e.getX(), e.getY());
}
}
public static void seekPrevious() {
final JTable table = TabelPanel.table;
if (table != null) {
final int total = table.getRowCount();
final int idx = table.getSelectedRow();
if (total == 0) {
return;
} else if ((idx == -1) && (total == 0)) {
return;
} else if ((idx == -1) && (total > 0)) {
table.setRowSelectionInterval(0, total - 1);
MediaUtils.switchMedia(table);
} else if (idx <= 0) {
table.setRowSelectionInterval(0, total - 1);
MediaUtils.switchMedia(table);
} else {
try {
table.setRowSelectionInterval(0, idx - 1);
MediaUtils.switchMedia(table);
} catch (final Exception e) {
table.setRowSelectionInterval(0, 0);
MediaUtils.switchMedia(table);
}
}
}
}
public static void seekNext() {
final JTable table = TabelPanel.table;
if (table != null) {
final int total = table.getRowCount();
final int idx = table.getSelectedRow();
if (total == 0) {
return;
} else if ((idx == -1) && (total == 0)) {
return;
} else if ((idx == -1) && (total > 0)) {
table.setRowSelectionInterval(0, 0);
MediaUtils.switchMedia(table);
} else if ((idx + 1) == total) {
table.setRowSelectionInterval(0, 0);
MediaUtils.switchMedia(table);
} else {
try {
table.setRowSelectionInterval(0, idx + 1);
MediaUtils.switchMedia(table);
} catch (final Exception e) {
table.setRowSelectionInterval(0, 0);
MediaUtils.switchMedia(table);
}
}
}
}
protected void displayRow(JTable table, int fromRow, int row) {
long reset_l = (long) table.getValueAt(row, HealthTableModel.RESET_COL);
long uptime = (long)table.getValueAt(row, HealthTableModel.UPTIME_COL);
//Log.println("RESET: " + reset);
//Log.println("UPTIME: " + uptime);
int reset = (int)reset_l;
updateTab((RadiationTelemetry) Config.payloadStore.getFramePart(foxId, reset, uptime, Spacecraft.RAD2_LAYOUT, false), false);
if (fromRow == NO_ROW_SELECTED)
fromRow = row;
if (fromRow <= row)
table.setRowSelectionInterval(fromRow, row);
else
table.setRowSelectionInterval(row, fromRow);
}
protected void displayRow(JTable table, int fromRow, int row) {
long type_l = 0;
long reset_l = (long) table.getValueAt(row, HealthTableModel.RESET_COL);
long uptime = (long)table.getValueAt(row, HealthTableModel.UPTIME_COL);
type_l = (long)table.getValueAt(row, HerciHSTableModel.TYPE_COL);
Log.println("RESET: " + reset_l);
Log.println("UPTIME: " + uptime);
Log.println("TYPE: " + type_l);
int reset = (int)reset_l;
int type = (int)type_l;
int headerType = 0;
if (table.getModel() instanceof HerciHSTableModel)
headerType = type + 200;
else {
type = (int)(type/1000);
headerType = type + 200; // FIXME - these hard coded numbers should be tied back to the base types 600 / 800
}
Log.println("Header Type: " + headerType);
this.hsPayload = (PayloadHERCIhighSpeed) Config.payloadStore.getFramePart(foxId, reset, uptime, type, Spacecraft.HERCI_HS_LAYOUT, false);
updateTab((HerciHighspeedHeader) Config.payloadStore.getFramePart(foxId, reset, uptime, headerType, Spacecraft.HERCI_HS_HEADER_LAYOUT, false), false);
if (fromRow == NO_ROW_SELECTED)
fromRow = row;
if (fromRow <= row)
table.setRowSelectionInterval(fromRow, row);
else
table.setRowSelectionInterval(row, fromRow);
}
protected void displayRow(JTable table, int row) {
long reset_l = (long) table.getValueAt(row, HealthTableModel.RESET_COL);
long uptime = (long)table.getValueAt(row, HealthTableModel.UPTIME_COL);
//Log.println("RESET: " + reset);
//Log.println("UPTIME: " + uptime);
int reset = (int)reset_l;
updateTab((RadiationTelemetry) Config.payloadStore.getFramePart(foxId, reset, uptime, Spacecraft.WOD_RAD2_LAYOUT, false), false);
table.setRowSelectionInterval(row, row);
}
protected void displayRow(JTable table, int fromRow, int row) {
long reset_l = (long) table.getValueAt(row, HealthTableModel.RESET_COL);
long uptime = (long)table.getValueAt(row, HealthTableModel.UPTIME_COL);
//Log.println("RESET: " + reset);
//Log.println("UPTIME: " + uptime);
int reset = (int)reset_l;
updateTab((RadiationTelemetry) Config.payloadStore.getFramePart(foxId, reset, uptime, Spacecraft.RAD2_LAYOUT, false), false);
if (fromRow == NO_ROW_SELECTED)
fromRow = row;
if (fromRow <= row)
table.setRowSelectionInterval(fromRow, row);
else
table.setRowSelectionInterval(row, fromRow);
}
private void notifyDataChanged(JTable table, int newIndex) {
fireTableDataChanged();
table.setRowSelectionInterval(newIndex, newIndex);
Rectangle rect = table.getCellRect(newIndex, 0, true);
table.scrollRectToVisible(rect);
}
public static void focusColumnTable(JTable table, int column) {
table.setColumnSelectionInterval(column, column);
table.setRowSelectionInterval(0, table.getColumnCount() - 1);
}
public static void focusCellTable(JTable table, int row, int column) {
table.setRowSelectionInterval(row, row);
table.setColumnSelectionInterval(column, column);
}
private void selectClickedCell(final MouseEvent e) {
Object source = e.getSource();
if (source instanceof JTable) {
JTable jSelectTable = (JTable) source;
Point point = e.getPoint();
if (!jSelectTable.getVisibleRect().contains(point)) { //Ignore clickes outside table
return;
}
int clickedRow = jSelectTable.rowAtPoint(point);
int clickedColumn = jSelectTable.columnAtPoint(point);
//Rows
boolean clickInRowsSelection;
if (jSelectTable.getRowSelectionAllowed()) { //clicked in selected rows?
clickInRowsSelection = false;
int[] selectedRows = jSelectTable.getSelectedRows();
for (int i = 0; i < selectedRows.length; i++) {
if (selectedRows[i] == clickedRow) {
clickInRowsSelection = true;
break;
}
}
} else { //Row selection not allowed - all rows selected
clickInRowsSelection = true;
}
//Column
boolean clickInColumnsSelection;
if (jSelectTable.getColumnSelectionAllowed()) { //clicked in selected columns?
clickInColumnsSelection = false;
int[] selectedColumns = jSelectTable.getSelectedColumns();
for (int i = 0; i < selectedColumns.length; i++) {
if (selectedColumns[i] == clickedColumn) {
clickInColumnsSelection = true;
break;
}
}
} else { //Column selection not allowed - all columns selected
clickInColumnsSelection = true;
}
//Clicked outside selection, select clicked cell
if ( (!clickInRowsSelection || !clickInColumnsSelection) && clickedRow >= 0 && clickedColumn >= 0) {
jSelectTable.setRowSelectionInterval(clickedRow, clickedRow);
jSelectTable.setColumnSelectionInterval(clickedColumn, clickedColumn);
}
}
}