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

The following examples show how to use javax.swing.JTable#requestFocus() . 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: HistoryMenuMouseListener.java    From ripme with MIT License 6 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
    if (e.getModifiers() == InputEvent.BUTTON3_MASK) {
        if (!(e.getSource() instanceof JTable)) {
            return;
        }

        tableComponent = (JTable) e.getSource();
        tableComponent.requestFocus();

        int nx = e.getX();

        if (nx > 500) {
            nx = nx - popup.getSize().width;
        }
        popup.show(e.getComponent(), nx, e.getY() - popup.getSize().height);
    }
}
 
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: PropertySheetTable.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent e) {
  JTable table = (JTable)e.getSource();
  if (!table.hasFocus()) {
    CellEditor cellEditor = table.getCellEditor();
    if (cellEditor != null && !cellEditor.stopCellEditing()) { return; }
    table.requestFocus();
    return;
  }
  ListSelectionModel rsm = table.getSelectionModel();
  int anchorRow = rsm.getAnchorSelectionIndex();
  table.editCellAt(anchorRow, PropertySheetTableModel.VALUE_COLUMN);
  Component editorComp = table.getEditorComponent();
  if (editorComp != null) {
    editorComp.requestFocus();
  }
}
 
Example 4
Source File: AnySelectionTableUI.java    From wandora with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
    super.mousePressed(e);
    
    if(!SwingUtilities.isLeftMouseButton(e)) {
        return;
    }

    JTable t = getTable();
    Point p = e.getPoint();
    int row = t.rowAtPoint(p);
    int column = t.columnAtPoint(p);
    int rowCount = t.getRowCount();
    int columnCount = t.getColumnCount();

    if(column < 0 || row < 0 || column >= columnCount || row >= rowCount ) {
        return;
    }

    TableCellEditor tce = t.getCellEditor();
    if((tce==null) || (tce.shouldSelectCell(e))) {
        t.requestFocus();
        updateTableSelectionModel(row, column, e.isControlDown(), e.isShiftDown(), false);
        t.repaint();
    }
}
 
Example 5
Source File: AnySelectionTableUI.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e) {           
    super.mouseDragged(e);

    if(!SwingUtilities.isLeftMouseButton(e)) {
        return;
    }

    
    JTable t = getTable();
    Point p = e.getPoint();
    int row = t.rowAtPoint(p);
    int column = t.columnAtPoint(p);
    int rowCount = t.getRowCount();
    int columnCount = t.getColumnCount();

    if(column < 0 || row < 0 || column >= columnCount || row >= rowCount ) {
        return;
    }

    TableCellEditor tce = t.getCellEditor();
    if(tce==null) {
        t.requestFocus();
        updateTableSelectionModel(row, column, e.isControlDown(), !e.isShiftDown(), true);
        t.repaint();
    }
}
 
Example 6
Source File: DataObjectTransferHandler.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean importData(JComponent c, Transferable transferable) {
    if (!canImport(c, transferable.getTransferDataFlavors())) {
        return false;
    }

    try {
        if (getDragComponent() != c) {
            List list = (List) transferable.getTransferData(dataFlavor);
            JTable table = (JTable) c;
            DesignerTablePanel.MyTableModel model = ((DesignerTablePanel.MyTableModel) table.getModel());
            int insertRow;
            if (getDropPoint() != null) {
                insertRow = table.rowAtPoint(getDropPoint());
            } else {
                insertRow = table.getSelectedRow();
            }

            for (int i = 0; i < list.size(); i++) {
                model.insertRow(insertRow + i, (Vector) list.get(i));
            }

            table.getSelectionModel().clearSelection();
            table.getSelectionModel().setSelectionInterval(insertRow, insertRow + list.size() - 1);
            table.requestFocus();
        }
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
Example 7
Source File: ButtonCellEditor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public boolean stopCellEditing() {
    String s = cell.toString();
    Window ancestorWindow = (Window)SwingUtilities.getRoot(cell);
    // #236458: options are now saved asynchronously. If the dialog was to 
    if (ancestorWindow == null) {
        return true;
    }
    // HACK: if this Editor creates a dialog, it will lose the focus and Swing
    // will remove the editor, calling JTable.cancelEditing. Any re-selections performed
    // by the JTable will occur BEFORE the dialog is finished, so we need to
    // reestablish the column selection later from here.
    // This binds the BCEditor to the KeymapTable layout / internals.
    JTable parent = (JTable)cell.getParent();
    
    ShortcutAction sca = (ShortcutAction) action;
    Set<ShortcutAction> conflictingAction = model.getMutableModel().findActionForShortcutPrefix(s);
    conflictingAction.remove(sca); //remove the original action
    
    Collection<ShortcutAction> sameScopeActions = model.getMutableModel().filterSameScope(conflictingAction, sca);
    
    if (!conflictingAction.isEmpty()) {
         if (!SwingUtilities.isEventDispatchThread()) {
             // #236458: options are now saved asynchronously, off EDT. If we display dialog, the IDE will lock up.
            cell.getTextField().setText(orig);
            fireEditingCanceled();
            return true;
         }
        //there is a conflicting action, show err dialog
        Object overrride = overrride(conflictingAction, sameScopeActions);
        
        // bring the focus back
        ancestorWindow.toFront();
        parent.requestFocus();
        if (overrride.equals(DialogDescriptor.YES_OPTION)) {
            for (ShortcutAction sa : conflictingAction) {
                removeConflictingShortcut(sa, s); //remove all conflicting shortcuts
            }
            //proceed with override
        } else if (overrride == DialogDescriptor.CANCEL_OPTION) {
            cell.getTextField().setText(orig);
            fireEditingCanceled();
            setBorderEmpty();
            return true;
        }
        // NO_OPTION fallls through and adds additional shortcut.
    }
    cell.getTextField().removeActionListener(delegate);
    cell.getTextField().removeKeyListener(escapeAdapter);
    model.getMutableModel().removeShortcut((ShortcutAction) action, orig);
    if (!(s.length() == 0)) // do not add empty shortcuts
        model.getMutableModel().addShortcut((ShortcutAction) action, s);
    fireEditingStopped();
    setBorderEmpty();
    model.update();
    return true;
}