JTable to react on key press like actionPerformed

I have a table with persons names, and if I press Enter key on cell with some name it should make some action. but i can not get to the cell value - evt.getSource() returns javax.swing.JTable but not the cell private class FileTableAdapter extends KeyAdapter {
  public void keyPressed(KeyEvent evt) {
      if(evt.getKeyCode() == evt.VK_ENTER)
      // this retuns a class javax.swing.JTable
    System.err.println(evt.getSource().getClass().toString());
}

You must get the row and column something like this.
Note I have not tried this.
If the evt.getSource() has a reference to the table.
int row = ((JTable)evt.getSource()).getSelectedRow();
int col = ((JTable)evt.getSource()).getSelectedColumn();
rykk

Similar Messages

  • What are the key presses like on the Enhanced Performance keyboard?

    Hi guys,
    I've been thinking about buying this keyboard:
    http://shop.lenovo.com/SEUILibrary/controller/e/gbweb/LenovoPortal/en_GB/catalog.workflow:item.detai...
    I was wondering how the key presses feel?   I'm quite particular about it.   I like the press to have a definite 'soft click' (like a cross between a microswitch and a diaphragm).    A lot of keys these days are like pressing a spring with no tactile response as to when a key press has actually been registered if that makes any sense.
    Can anyone with this keyboard describe how the keys are to press?   I can't find and videos or any real life examples to test.
    Thanks,
    Leo

    if you are looking for tactility in a keyboard, than this keyboard is not the best. Maybe you should get a Filco keyboard instead.
    Microsoft and Dell's keyboard (the one with oversized spacebar) are both slightly better than these Lenovo keyboard. Alternatively get the Space Saver II keyboard. 
    Regards,
    Jin Li
    May this year, be the year of 'DO'!
    I am a volunteer, and not a paid staff of Lenovo or Microsoft

  • What is the shortcut to maximize window (full screen) which is normally done by pressing " -- " like key on the right top corner in macbook pro ?

    What is the shortcut to maximize window (full screen) which is normally done by pressing "<-->" like key on the right top corner in macbook pro ?

    There's no <--> key on ANYones keyboard. (Great answer Shootist )
    The other part of his answer is only applicable to certain windows (browsers specifically) as there is NO system wide maximize command in the manner you are asking.
    Apple's "maximize" function (green +) simply maximizes the window to the content, not the screen.
    For other keyboard shortcuts (and of course they may be outdated) try: this

  • How to listen to key press in JTable

    I've been trying to listen to key press in JTable,
    However it only works if the cell is double-clicked.
    If the tab button is use or the cell is single-clicked, nothing happens to the listener.
    Anybody can help me???
    Thanks

    table.getColumnModel().addColumnModelListener(new TableColumnModelListener(){
      public void columnAdded(TableColumnModelEvent e){}
      public void columnMarginChanged(ChangeEvent e){}
      public void columnMoved(TableColumnModelEvent e){}
      public void columnRemoved(TableColumnModelEvent e){}
      public void columnSelectionChanged(ListSelectionEvent e){
        // column selection changed
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
      public void valueChanged(ListSelectionEvent event) {
        // row selection changed
    });rykk

  • I like the "whites" and "blacks" sliders in lightroom with the option key pressed- is there a corresponding slider in aperture? thank you

    i like the "whites" and "blacks" sliders in lightroom with the option key pressed- is there a corresponding slider in aperture? thank you

    There's no exact analogue to the "whites" slider in Aperture.  But you could do it with curves if you wanted.  You can set the white point using the curves tool as well.

  • Amount of key presses a user makes over time - BPM

    Hi,
    Im working on a small program that needs to get the amount of keypresses a user makes over time.
    Basically its for calcuating the BPM a user is inputting. So a uers taps a beat for 5 seconds and the amount of tap is saved and multiplied by 12 to get the Users BPM.
    So far i have this:
    package Version1;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.util.Timer;
    import java.util.TimerTask;
    import javax.swing.*;
    public class muTap extends JFrame implements KeyListener, ActionListener {
        JTextArea display;
         * main - the main method
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    theGUI();
         * muTap constructor
        public muTap(String name) {
            super(name);
         * theGUI - creates the gui for muTap
        public static void theGUI() {
            muTap frame = new muTap("muTap");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Set up the content pane.
            frame.addComponents();
            //Display the window.
            frame.pack();
            frame.setVisible(true);
         * adComponents - adds gui components to muTap
        public void addComponents() {
            JButton button = new JButton("Start");
            button.addActionListener(this);
            display = new JTextArea();
            display.setEditable(false);
            display.addKeyListener(this);
            JScrollPane scrollPane = new JScrollPane(display);
            scrollPane.setPreferredSize(new Dimension(375, 125));
            getContentPane().add(scrollPane, BorderLayout.PAGE_START);
            getContentPane().add(button, BorderLayout.PAGE_END);
        public void keyTyped(KeyEvent e) {
            //Do Nothing
        /** Handle the key pressed event from the text field. */
        public void keyPressed(KeyEvent e) {
            //TODO call the getBPMfromKboard() method
            taps++;
            System.out.println("Tap: " + taps);
        /** Handle the key released event from the text field. */
        public void keyReleased(KeyEvent e) {
            //Do Nothing
        /** Handle the button click. */
        public void actionPerformed(ActionEvent e) {
            //Do Nothing
            //initialCountdown(3, "Start Tapping Fool");
            countDown(3);
         * countDown - a simple countdown timer for use when getting users input.
         * @param time amount of time to count down from
         * @return      true when timer ends.
        public static int taps;
        public void countDown(final int time) {
            taps = 0;
            final Timer timer = new Timer();
            timer.scheduleAtFixedRate(new TimerTask()
                int i = time;
                public void run()  {
                    i--;
                    String s = Integer.parseInt(i); // error because of this i.
                    display.setText(s);
                    if (i < 0) {
                        timer.cancel();
                        if(time == 3)
                            display.setText("Start Tapping");
                            countDown(5);
                        else if(time == 5)
                            display.setText("Number of taps: " + taps);
                            //System.out.print("Number of taps" +taps);
            }, 0, 1000);
    }But i get errors when i try running it:
    "Exception in thread "Timer-1" java.lang.RuntimeException: Uncompilable source code"
    It doesnt seem to like me parsing int to string here:
    String s = Integer.parseInt(i); Any ideas? or if youve got suggestions on another way to do it it'd be much appreiated.
    Thanks!

    Korvanica wrote:
    It doesnt seem to like me parsing int to string here:
    String s = Integer.parseInt(i);
    Yikes, you've got that bit of code backward, there partner.
    You use Integer.parseInt to parse a String into an int, not the other way around.
    If you want to change an int to a String, do
    String s = String.valueOf(i)or you can use the various formatters out there.

  • How to get the actual key pressed in a UITextField

    Hi all , now i develop a program on iphone SDK 3.0 GM.
    I have an UITextField (created programmatically) and I have implemented the delegate as well as the UITextFieldTextDidChangeNotification so that I can react to changes in the text values.
    However, I specifically want to know when the user presses the backspace key in the UITextField when there is currently no text in the field. I can't find where I can get a specific notification of the actual key pressed, as opposed to the resulting state of the text. I'm sure there is a way to do this...help?

    I can imagine why you want to do it. I had the same problem myself and managed to circumvent it in a slightly painful way. What I did was to subclass UITextField to create a text field that always had text in it, even when it "seemed" empty. In fact the first character of the text is a space character, and then what follows is the actual text. In this way, your delegate will always get called about a backspace (when it's an attempt to delete the leading space character, obviously you should return NO in the textField: shouldChangeCharactersInRange: replacementString: method). I won't get into the details of exactly how to set everything up, like I said it is kind of elaborate and I wouldn't really recommend it unless you are desperate to have that kind of functionality.

  • Using InputMap and ActionMap to detect any key pressed...plz help

    Hi,
    I am quite new to Java. I have a tiny problem. I wanna put an actionlistener into a JTextField, so it printout something whenever a key is pressed (when the textField is selected).
    I can only get it to print if I assign a specific key to pressed...example below (works):
    JTextField searchBox = new JTextField();
    InputMap imap = searchBox.getInputMap();
    ActionMap amap = searchBox.getActionMap();
    imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, 0), "pressed");
    amap.put("pressed", new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                   System.out.println("TYPEEEEEEEEEEEEEEE");
    HOWEVER, when i change keystroke to any key pressed, it doesn't work. Example below(doesn't work):
    JTextField searchBox = new JTextField();
    InputMap imap = searchBox.getInputMap();
    ActionMap amap = searchBox.getActionMap();
    imap.put(KeyStroke.getKeyStroke(KeyEvent.KEY_PRESSED, 0), "pressed");
    amap.put("pressed", new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                   System.out.println("TYPEEEEEEEEEEEEEEE");
    Somebody plz helps me. I am really confused how to use KeyEvent.KEY_PRESSED. I thought it would work the same way as KeyEvent.VK_A...if i can't use KEY_PRESSED for that purpose, what KeyEvent do I use?
    Thank you very much in advance.

    Sounds like you want a KeyListener.
    textField.addKeyListener(new KeyListener() {
        public void keyTyped(KeyEvent e) {
            System.out.println("Key typed.");
        public void keyPressed(KeyEvent e) {
            System.out.println("Key pressed.");
        public void keyReleased(KeyEvent e) {
            System.out.println("Key released.");
    });See the API documentation for more information.

  • Key Press CTRL+Space

    How do I view a JInternalFrame by pressing CTRL+Space from a JTextFeild in another JInternalFrame? Using isControlDown() works but throws NullPointerException. Can it be done by using KeyStroke ? If Yes then how?

    Thanks! I changed the InternalFrame which I wanted to see after pressing. I used A JPanel in which there is a JList. What I tried is pretty simple and like this
    private void jTextFieldlBankIDKeyPressed(java.awt.event.KeyEvent evt) {
    try{
    int keyCode=evt.getKeyCode();
    int modifier=evt.getModifiers();
    int iSpace=java.awt.event.KeyEvent.VK_SPACE;
    if(evt.isControlDown()&& keyCode==iSpace){
    jPanel2.setVisible(true);
    //setValueAtTheList();
    //jList1.grabFocus();
    System.out.println("Key Pressed");
    }catch(NullPointerException e){
    I got what I need but the exception is there like before,
    java.lang.NullPointerException
    at javax.swing.plaf.basic.BasicInternalFrameUI$1.actionPerformed(BasicInternalFrameUI.java:153)
    at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1502)
    at javax.swing.JComponent.processKeyBinding(JComponentKey Pressed
    .java:2422)
    at javax.swing.KeyboardManager.fireBinding(KeyboardManager.java:253)
    ������������.

  • How to reach Combobox Items via Key pressed (Java5)

    Hallo all,
    I have a question. I have a JCombobox field and assume that it has its items like (Apple, Banana, Pear). How can I manage to jump into Pear item by pressing P in that combobox?

    I am sorry I was wrong. I had to tell that my Combobox value is in my Table and the CellListener doesn't allow to do that. If I am gonna have another Swing problem I am going to send my message to that forum. I don't want to duplicate this question right now. Here is my code.
        public void load() {
            serviceType = data.getMetadata(position).getMetadataValuesSorted().toArray(new MetadataValue[0]);
            String[] metadataValues = new String[serviceType.length];
            for (int i = 0; i < serviceType.length; i++) {
                MetadataValue values = serviceType;
    metadataValues[i] = values.getValue();
    final TableColumn col2 = table.getColumnModel().getColumn(1);
    col2.setCellEditor(new MetadataValueComboBoxEditor(serviceType));
    col2.setCellRenderer(new MetadataValueComboBoxRenderer(serviceType));
    public class MetadataValueComboBoxRenderer extends JComboBox implements TableCellRenderer {
    public MetadataValueComboBoxRenderer(final MetadataValue[] items) {
    super(items);
    final JComboBox newItems = new JComboBox(items);
    setRenderer(new DefaultListCellRenderer() {
    public Component getListCellRendererComponent(final JList list, Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
    if (value != null && value instanceof MetadataValue) {
    value = ((MetadataValue) value).getValue();
    final String valueString = (String)value;
    newItems.addKeyListener(new KeyAdapter() {
    public void keyTyped(KeyEvent e) {
    for (int i = 0; i < items.length; i++) {
    if (e.getKeyChar() == valueString.charAt(0)) {
    newItems.setSelectedItem(newItems.getComponent(i));
    return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    registerComponent(this);
    public Component getTableCellRendererComponent(final JTable table, final Object value,
    final boolean isSelected, final boolean hasFocus, final int row, final int column) {
    if (isSelected) {
    setForeground(table.getSelectionForeground());
    super.setBackground(table.getSelectionBackground());
    } else {
    setForeground(table.getForeground());
    setBackground(table.getBackground());
    setSelectedItem(value);
    return this;
    public class MetadataValueComboBoxEditor extends DefaultCellEditor {
    public MetadataValueComboBoxEditor(final MetadataValue[] items) {
    super(new JComboBox(items));
    final JComboBox newItems = new JComboBox(items);
    registerComponent((JComponent) this.getComponent());
    ((JComboBox) getComponent()).setRenderer(new DefaultListCellRenderer() {
    public Component getListCellRendererComponent(final JList list, Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
    if (value != null && value instanceof MetadataValue) {
    value = ((MetadataValue) value).getValue();
    final String valueString = (String)value;
    newItems.addKeyListener(new KeyAdapter() {
    public void keyTyped(KeyEvent e) {
    for (int i = 0; i < items.length; i++) {
    if (e.getKeyChar() == valueString.charAt(0)) {
    newItems.setSelectedItem(newItems.getComponent(i));
    return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    MetadataValueComboBoxEditor  and MetadataValueComboBoxRenderer inner classes doesn't allow me to select the item via key pressed.
    Edited by: NEO1976 on Mar 24, 2008 10:11 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Key Press Not Responding If You Go Back (re-do step)

    I have a software simulation in which one of the steps is to enter some numbers into a text field and press the Enter key. Works good on the first pass. If you then click the Back button and go back to a previous step the Enter key will no longer work. I have search the forums and some blogs without any luck.
    Example:
    http://elearning.biworldwide.com/misc/Soft_Sim/Soft_Sim.htm
    After you reach the text entry step and enter the correct numbers and press Enter, click the Back button (lower left) and back up to the Click Member step and re-preform the steps. When you reach the text entry the Enter key press will no longer work.
    Source CP4 file:
    http://elearning.biworldwide.com/misc/Soft_Sim/Soft_Sim.zip
    Thanks for any assistance,
    Kevinhttp://elearning.biworldwide.com/misc/Soft_Sim/Soft_Sim.htm

    All apps in the recently used apps bar or dock which is accessed by pressing the home button twice are not loaded and running. Some apps like games that have been updated to do so will be in an idle state, most will be quit, and some will run in the background when leaving the app. The number of apps that can run in the background are very few and far between because there is no reason or benefit for the overwhelming number of 3rd party apps to run in the background.
    http://whenwillapple.com/blog/2010/04/19/iphone-os-4-multitasking-explained-agai n/

  • Why i am unable to catch the 'TAB' key press?

    hi
    i have an application where i have 2 text fields and one button in order say t1, t2 and b1.
    on tabbing t1 cursor moves to t2 and on tabbing t2 cursor moves to b1 and on tabbing b1 cursor moves to t1.
    now when i press tab button on any of the component i have written a keyListener for that to catch 'TAB' key using the comparision
    if( e.getKeyCode() == KeyEvent.VK_TAB )
    but its not catching the tab key pressed on any of these 3 components....
    why like this...
    i want to catch the press of 'TAB' key and write some action for it... but unable to catch the 'TAB' key press.
    anyone could help me in this....
    thanx in advance,
    -Soni

    I seem to remember this question being asked before. I think the answer was that the FocusManager intercepts the TAB key. I don't remember the solution but you can try searching the forum.

  • Changing images based on keys pressed

    Ok, I'm trying to make my character face a different direction when a key is pressed (when left is pressed, he faces left, when right is pressed, he is facing right). Right now I am going to load all the images into an array and then tell it which one to paint based on the key pressed. Anything faster or better?
    Thanks!
    -Brian

    Hmmm, javax. The javax packages usually accompany
    pain and torture... eerrrr, swing. I detest swing. I
    will use this for now, but do you know of any other
    ways to do this? Or is this not related to swing?The javax package contains alot more than Swing.
    Saying all javax packages are painful to use, simply because you don't like swing is silly.
    As for answering your question. Try re-reading the post by KarateMarc.
    You can either use MediaTracker (horrible, but it will let you know when the image is loaded) or ImageIO to properly load your images.

  • How to detect any key pressed for program running in the background?

    Hi All,
    is it possible to detect when any key is pressed if a java program is not in the focus? For example, when I have a console based program I can write something like:
    System.in.read();
    and wait until any key is pressed. However, if I move the mouse away from the console and make any other window active, the console program "doesn't hear" anything. Ok, it's clear, of course, but how is it possible to make the program detect any keys pressed even if it's running in the background?
    Thanks a lot for any hints!

    qnx wrote:
    1) Stop trying to make spyware. -> I don't do anything like this!
    2) Stop re-posting the same questions. -> didn't know they are the same, sorry.
    3) Stop taking us for fools. -> what? Honestly, I don't think that I realy deserved this :)With a limited posting history and the type of questions you are asking they are unusual.
    There are very few legitimate problem domains that would require what you are asking about. There are illegitimate ones though. And the legitimate ones would generally require someone with quite a bit of programming experience and would also be required (the fact that java can't do it would not get rid of the requirement.)
    Thus one might make assumptions about your intentions.

  • Simultaneous ASDW key press undetected

    Hi guys, I'm currently developing a game that uses ASDW buttons for its movement system
    During one of my testing session, i realized that if i press 2 buttons simultaneously, (ex: A and S), both events would be dispatched one after the other (just like what i assume they would do)
    But if i press 3 buttons simultaneously, (ex: A, S and D), the last keypress (D) will go undetected
    Only after i release one of the keys (either A or S) will the last keypress be detected
    From what i read here ==> http://blog.nobien.net/2008/05/12/more-than-two-simultaneous-key-presses-and-keyboardevent key_down-woes/
    It is said that the problem might had been caused by a hardware issue
    From what i read at wikipedia http://en.wikipedia.org/wiki/Keyboard_%28computing%29
    [quote]
    Some low-quality keyboards suffer problems with rollover (that is, when multiple keys are pressed in  quick succession); some types of keyboard circuitry will register a  maximum number of keys at one time. This is undesirable for games (designed for multiple keypresses, e.g. casting a spell while holding  down keys to run) and undesirable for extremely fast typing (hitting new  keys before the fingers can release previous keys). A common side  effect of this shortcoming is called "phantom key blocking": on some  keyboards, pressing three keys simultaneously sometimes resulted in a  4th keypress being registered.
    Modern keyboards prevent this from happening by blocking the 3rd key  in certain key combinations, but while this prevents phantom input, it  also means that when two keys are depressed simultaneously, many of the  other keys on the keyboard will not respond until one of the two  depressed keys is lifted. With better keyboards designs, this seldom  happens in office programs, but it remains a problem in games even on  expensive keyboards, due to wildly different and/or configurable  key/command layouts in different games.
    [/quote]
    Question
    - What causes this problem is it a hardware issue or a language/flash player problem?
    Because i might be wrong, but i think i've played several non-flash games before that possess the ability to address multiple keypress at the same time
    - Can this problem be fixed?
    Code
    package
            import flash.display.Sprite;
            import flash.events.KeyboardEvent;
            public class Keyboard extends Sprite
                     public function Keyboard()
                            this.stage.addEventListener("keyDown", showKey);
                    public function showKey(event:KeyboardEvent)
                            trace(event.keyCode);
    Any help regarding the matter is greatly appreciated, thank you in advance~

    Quote
    do you think an update of the bios will do the trick?
    No, no, no, it won't, so please don't try it!
    Also, if you read the comments in the link you posted, your answer is there:
    Quote
    By Tony Fendall on May 12, 2008 | Reply
    The problem comes from the way in which the signal for the pressed keys moves from your keyboard to your computer. The signal is only 8-bit, and there are limits to how the signal can be changed to represent more than one key being pressed in combination.
    Long story short, the guys who designed the origional keyboards made a descision to support all two key combinations, and then selected as many three key combinations as they could support with the hardware. This meant that some combinations had to be left out, and they had to make a descision about which ones were more important.
    It just happens to be that they chose not to support three key combinations which involve the up arrow key. I do not think there is any solution to this problem…
    If you're playing games, why not just remap the keys in the game's settings?

Maybe you are looking for

  • Is it possible to do a 100 minute edit and then export to mpeg 2 or h264.

    I'm having difficulty with a long edit - 100 minutes or so.  It keeps quitting during the export.  Have now cut it down to two separate files but having difficulty opening the mpeg 2 file.  Any suggestions?  Thanks, Jo

  • How do I capture a tv show from my dvr to my mac

    I have a mac book pro and I would like to take tv shows I have recorded on my dvr and record them to my mac. What hardware and software do I need to us?

  • How to deploy custom development with JDI

    We use JDI to deploy webdynpro for ESS application. for that we create a track, check in ESS components in the track and set up run time systems. now we are going to do custom development, for example: create interactive forms, etc.. we would like to

  • BPM integration with BRM

    Hi All, I am looking for a blog for complete scenario which includes business rules used in BPM,that is ,complete STEP BY STEP blog for BPM integration with BRM.Searched a lot but finding either BPM or BRM or BRM already created without mentioning st

  • Maximum number of RAC services in a Node

    DB, Grid Version: 11.2.0.3/RHEL 5.4 My question is on the preferred node for a RAC service. What is the maximum number of RAC services that can created in a node ?