下面列出了javax.swing.JTable#getSelectedColumn ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
}
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();
}
}
/**
* Adding column is done by creating new model by modifying older one.<p>
*
* Insert new column if column is outside the <code>limit</code> Adds new
* column if selected column inside the <code>limit</code>[email protected] _table
* target table
*
* @param limit the range to avoid inserting
*/
static void addcol(JTable table, int limit) {
try {
int sc = table.getSelectedColumn();
if (sc < limit - 1) {
sc = table.getColumnCount() - 1;
}
DefaultTableModel tableM = (DefaultTableModel) table.getModel();
DefaultTableModel tableM1 = new DefaultTableModel();
TableModelListener[] listeners = tableM.getTableModelListeners();
tableM1.setDataVector(newvectoraddcol(tableM.getDataVector(), sc), getColumnIdentifiersaddcol(sc + 1, table));
table.setModel(tableM1);
for (TableModelListener l : listeners) {
tableM1.addTableModelListener(l);
}
} catch (Exception ex) {
Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, ex);
}
}
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(Utility.encrypt(data), row, col);
}
} catch (HeadlessException ex) {
Logger.getLogger(TMSettingsControl.class.getName())
.log(Level.SEVERE, ex.getMessage(), ex);
}
}
};
}
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);
}
}
};
}
public JMenu getMenu(final JTable jTable, final List<E> items) {
String text = null;
EnumTableColumn<?> column = null;
boolean isNumeric = false;
boolean isDate = false;
int columnIndex = jTable.getSelectedColumn();
if (jTable.getSelectedColumnCount() == 1 //Single cell (column)
&& jTable.getSelectedRowCount() == 1 //Single cell (row)
&& items.size() == 1 //Single element
&& !(items.get(0) instanceof SeparatorList.Separator) //Not Separator
&& columnIndex >= 0 //Shown column
&& columnIndex < getShownColumns().size()) { //Shown column
column = getShownColumns().get(columnIndex);
isNumeric = isNumeric(column);
isDate = isDate(column);
text = FilterMatcher.format(getColumnValue(items.get(0), column.name()), false);
}
return new FilterMenu<E>(gui, column, text, isNumeric, isDate);
}
@Override
public JPopupMenu createPopupMenu(int row, int column, Node[] selectedNodes, Component component) {
JPopupMenu popup = super.createPopupMenu(row, column, selectedNodes, component);
if (column > 0 && selectedNodes.length == 1) {
JTable table = (JTable) component;
if (table.getSelectedColumn() > 0) {
TableTupleNode tuple = (TableTupleNode) selectedNodes[0];
if (tuple.isMcResultNode()) {
String columnName = table.getColumnName(column);
Cell c = tuple.getCell(columnName);
if (c.getValue().getType().equals(SpeedyConstants.LLUN)) {
popup.add(separator);
popup.add(cellGroup);
}
}
}
}
return popup;
}
private MouseListener createExpressionEditorMouseListener(final JTable table, final boolean booleanExpected) {
final MouseAdapter mouseListener = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
final int column = table.getSelectedColumn();
if (column == 1) {
table.removeEditor();
final int row = table.getSelectedRow();
final String[] value = new String[]{(String) table.getValueAt(row, column)};
final int i = editExpression(value, booleanExpected);
if (ModalDialog.ID_OK == i) {
table.setValueAt(value[0], row, column);
}
}
}
}
};
return MouseEventFilterFactory.createFilter(mouseListener);
}
@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);
}
}
}
private static boolean find2(JTable table, String searchPhrase,
boolean forward, boolean matchCase) {
if (table == null)
throw new NullPointerException(
"No table component was provided to search.");
if (searchPhrase == null)
throw new NullPointerException(
"No search phrase was provided to search for.");
if (searchPhrase.length() == 0)
return false;
if (matchCase == false)
searchPhrase = searchPhrase.toUpperCase();
int selectedColumn = table.getSelectedColumn();
int selectedRow = table.getSelectedRow();
int[] selection = new int[] { selectedRow, selectedColumn };
if (find(table, searchPhrase, forward, matchCase, true, selection)) {
// if the selection doesn't change, do nothing.
if (selectedRow == selection[0] && selectedColumn == selection[1])
return false;
table.changeSelection(selection[0], selection[1], false, false);
highlight(table, selection[0], selection[1]);
return true;
}
return false;
}
/**
* 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));
}
@Override
public void mousePressed(MouseEvent e) {
if (e.getClickCount() == 2) {
JTable source = (JTable) e.getSource();
if (e.getSource() == certTable && source.getSelectedColumn() != 2) {
certControll.showCertificate();
}
}
if(e.getSource() == certTable){
showCert.setEnabled(true);
}
}