Java Code Examples for javax.swing.JTable#getSelectedColumn()

The following examples show how to use javax.swing.JTable#getSelectedColumn() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RTable.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
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;
    }
}
 
Example 2
Source File: BaseTable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example 3
Source File: JtableUtils.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
/**
 * 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>table@param _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);
    }

}
 
Example 4
Source File: XTablePanel.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
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);
            }

        }
    };
}
 
Example 5
Source File: TMSettingsControl.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
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);
            }

        }
    };
}
 
Example 6
Source File: FilterControl.java    From jeveassets with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example 7
Source File: TablePopupFactory.java    From Llunatic with GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example 8
Source File: MosaicExpressionsPanel.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
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);
}
 
Example 9
Source File: TableCellDrag.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example 10
Source File: SwingSearch.java    From pumpernickel with MIT License 5 votes vote down vote up
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;
}
 
Example 11
Source File: ExcelSheetSelectionPanelModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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));
}
 
Example 12
Source File: CertificatesManagerSettingsPanel.java    From Spark with Apache License 2.0 5 votes vote down vote up
@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);
	}
}