Using the keyboard to activate a button

Say I have a JTextfield and a JButton. I want the Enter key to do the same thing as clicking on the JButton. I thought there might be a way to do it by having the JTextfield watch for "/n", but I couldn't figure it out. I searched ActionEvent in the documentation, and I didn't find much help there either.

Hmm... JTextField supports ActionListeners, the same as a JButton, so if you register an ActionListener with the field, hitting enter is supposed to fire an ActionEvent.
ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent ae) {
System.out.println(ae.getSource());
JTextField tf = new JTextField();
tf.addActionListener(al);
JButton bt = new JButton("enter");
bt.addActionListener(al);

Similar Messages

  • I have a macbook pro. i think i might have pushed some buttons that made my macbook look for a wireless keyboard.. i dont have any wireless keyboard. and now i cant use the keyboard on my macbook. how can i get the normal keyboard staring?

    i have a macbook pro. i think i might have pushed some buttons that made my macbook look for a wireless keyboard.. i dont have any wireless keyboard. and now i cant use the keyboard on my macbook. how can i get the normal keyboard staring?

    korgba wrote:
    it pops up a script were it says that the macbook cannot find a bluetooth keyboard, and it isnt a keyboard connected
    For some reason, your Mac doesn't recognise that a keyboard is present, so it looks for a wireless keyboard. The question is, why doesn't your Mac recognise that a keyboard is attached?
    First, you need to make sure you remove all peripherals, especially USB peripherals (the keyboard is on the USB bus). Then restart holding down the Shift key. This should boot in Safe mode. If the computer boots normally (not in safe mode) and the keyboard is still not working, try resetting the SMC
    Intel-based Macs: Resetting the System Management Controller (SMC)
    <http://support.apple.com/kb/HT3964>
    If that still doesn't fix the problem, then the keyboard (or its controller) is probably damaged and needs to be replaced.

  • Hello, my backspace and enter keys suddenly stopped working. I have done a PRAM reset and used the keyboard viewer to see if the buttons work and they don't.  The PRAM reset didn't work  either

    Dear All,  the backspace and enter keys on my wireless keyboard suddenly stopped working.  Im using OS 10.7.5 and have tried a PRAM reset which didn't work.  I also used the keyboard viewer to see if the keys worked on that but they don't.  This is driving me mad, can anyone please tell me what to do?  It happened just after an update but this could be a coincidence.  Thank you for your time 

    For my computers, though some of them support BlueTooth devices and accessories,
    my preference and economy of standard, is to have wired USB and also use powered
    USB hubs for accessories.
    I've used USB wired keyboards and mouse products; and some I've bought from the
    original owners who had upgraded to BT, and never used the new Apple USB model;
    so I have spares of these on-hand since they seldom fail, but do work when BT won't.
    {A SMC reset should not cause a problem, or seldom has; but can solve some.}
    In my opinion, the wired USB keyboard is an essential accessory, if not a necessary
    primary means of user access on a continuous basis. At least until the wires fail...!

  • Hi. After I have loaded a picture into Photoshop some of the menu tools are greyed out and I cannot use the keyboard short cut, for instance I cannot use Ctrl   T to enter free transform mode. Also the toolbar is so small I cannot see the icons without ge

    Hi. After loading a picture into Photoshop some of the menu tools are greyed out and I cannot use the keyboard short cuts, for instance I cannot use Ctrl + T for free transform, how do I resolve this problem. In addition the tool Icons are so small I have to get close to the screen to see them, is there anyway the Icons can be made bigger without reducing the resolution of the screen.
    Thanks
    Derek

    Are you working on a background layer? If so, Ctrl + T will not work. Press Alt and double-click your background layer to convert to a normal layer (or right-click BG layer and select Layer from Background) and try again.
    If you're working in Photoshop CC 2014 you can go to Preferences > Experimental Features and tick "Scale UI 200% for high-density displays" to make your buttons and icons larger.

  • Bottom row of the keyboard is not working in a vertical orientation on the iPhone 3Gs. the "slide to unlock" and all keys on the calculator on both orientation works fine. I can use the keyboard on horizontal orientation.

    Bottom row of the keyboard is not working in a vertical orientation on the iPhone 3Gs. the "slide to unlock" and all keys on the calculator on both orientation works fine. I can use the keyboard on horizontal orientation. The tabs on bottom of all apps also work fine.
    I have already tried holding down the power button and home button for 10 seconds, but no difference.

    I've had this problem on and off for the last few weeks (around, but not directly related, to upgrade to 6.1...can't remember if was before or after)....I'm very convinced it's a software problem (as there have been times when the bottom row works perfectly, without any need to "press" differently or anything).
    However, it seems to be a rather resilient software issue, as a full restore does not consistently fix it, and it applies to more than just the keyboard; if I open a drawing app, there's definitely a row (about 4mm up from the edge of the screen closest to home button) where I cannot draw.
    It's happened 4 times now.  Originally it went away with a restore from backup, then worked for 2 more days.  The second and third times, it went away with a full restore (although I did two full restores in between those two restores that did nothing, so restore didn't consistently fix it)....and it seemed to return in the most random of circumstances. 
    I paid very close attention to what apps I was using the last time it was working so that I could spot which app, if any, might be causing the issue.  I deleted several apps, I stopped using the games and many other apps.   I only used three apps between it working fine and starting up as a problem again: mail, safari and messages.
    I was convinced it was mail, as it happened this morning when I picked up my phone off the bedside table to respond to a new email.  It was working when I went to bed.  I picked up the phone when it buzzed, hit the email app, hit reply and started to type....**** bottom row wasn't working again.
    However, tonight I did 2 things....one of them worked because it went back to normal (sorry, I don't know which as I was exasperated and trying a number of things). 
    The two things I did between a broken keyboard and a working keyboard were:
    1) adding a second keyboard (English(Canada)), changing to this keyboard, and changing back
    2) disabling Siri...and then turning it back on...and then disabling Siri's "Raise to Speak"
    In retrospect, I wonder if it actually was the "Raise to Speak" that was putting the phone into a weird state, and might explain why the phone would just "suddenly" start behaving strangely when I picked it up.  Of note, the "raise to speak" hasn't actually triggered Siri to come on in months anyway.
    Regardless, the keyboard is back to normal now...and I'm just going to leave "Raise to Speak" off.  I've put the keyboard back to just "English" with no alternates and Siri remains on otherwise without issue.

  • Is there a way to move to the previous folder by using the keyboard?

    Is there a way to move to the previous folder by using the keyboard? Just the same as clicking the left arrow at the top left of the Finder window? I know how to do this in Windows (press and hold the Alt key and press the left arrow key.)
    Is this possible in MacOSX?
    Thanks,
    Jeff

    Command-Up Arrow is not the same as the left arrow button in the tool bar. Command-Up Arrow moves up one folder in the file system hierarchy. To go back, use Command-[.

  • The keybord of my Ipod 5th was fine until I update to ios 7, now i can not use the keyboard because it took like 15seconds to the letters to appear

    They keyboard of my Ipod 5th was exellent until I update to ios7, now i cannot use the keyboard because it took like 15 seconds to the letters to appear

    Try:
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings      
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                 
    iOS: How to back up                                                                
    - Restore to factory settings/new iOS device.      

  • Pausing ITunes Playback Using The Keyboard

    Friends,
    When playing a song in ITunes, I can stop playback by moving the mouse over the pause button in the top left-hand corner of the ITunes window, and left-clicking. How can I accomplish this same action using the keyboard?
    Thanks much,
    Tom Hesley

    Looks like hitting the space bar actuates the play / pause button in ITunes.
    Tom Hesley

  • Hello, I have a macbook pro late 2011 15 inch with 4 gb ram. My macbook runs extremely slow when logging in after waking up from sleep, locking up and I am unable to use the keyboard. Is there a fix?

    My macbook runs extremely slow when logging in after waking up from sleep, locking up and I am unable to use the keyboard. Furthermore, when just using safari to watch streaming television, my computer gets really slow, and locks up, and the dock appears blank and I sit here frustrated. Anytime i wake up my computer, my keys don't respond and I've waited at most 3 minutes untill i can type in my password. Even sometimes when i type in my password and hit enter, it takes forever to open up my mac. I have barely used any storage in my macbook, since i only use it for college, and I have run clamscan wiht no viruses showing... Any ideas?

    when just using safari to watch streaming television, my computer gets really slow, and locks up, and the dock appears blank
    Please read this whole message before doing anything.
    This procedure is a diagnostic test. It’s unlikely to solve your problem. Don’t be disappointed when you find that nothing has changed after you complete it.
    The purpose of the test is to determine whether the problem is caused by third-party software that loads automatically at startup or login, or by a peripheral device. 
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards. Boot in safe mode and log in to the account with the problem. Note: If FileVault is enabled, or if a firmware password is set, or if the boot volume is a software RAID, you can’t do this. Ask for further instructions.
    Safe mode is much slower to boot and run than normal, and some things won’t work at all, including sound output andWi-Fi on certain iMacs. The next normal boot may also be somewhat slow.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin. Test while in safe mode. Same problem? After testing, reboot as usual (i.e., not in safe mode) and verify that you still have the problem. Post the results of the test.

  • Unable to use the keyboard in XP keys work OK when boot into dos

    Unable to use the keyboard in XP. It was working for over a year OK  with XP running
    keys work OK when I install win98 or use a dos boot disk.
    If I try to reinstall XP I can not use any of keys to input anything.
    Return
    Esc
    CapsLock
    ctrl-alt-del.
    NO KEYS WORK AT ALL OTHER THAN 
    ë à
    I did an upgrade from win98 but that did not work.
    Any ideas

    billwyatt, welcome to the forum,
    I think you forgot to mention which ThinkPad you have. It would be even better if you could post the Type and Model Number as this will help members to hopefully help you. If it ends in CTO please provide some details about the ThinkPad. Please do NOT post your s/n.
    Andy  ______________________________________
    Please remember to come back and mark the post that you feel solved your question as the solution, it earns the member + points
    Did you find a post helpfull? You can thank the member by clicking on the star to the left awarding them Kudos Please add your type, model number and OS to your signature, it helps to help you. Forum Search Option T430 2347-G7U W8 x64, Yoga 10 HD+, Tablet 1838-2BG, T61p 6460-67G W7 x64, T43p 2668-G2G XP, T23 2647-9LG XP, plus a few more. FYI Unsolicited Personal Messages will be ignored.
      Deutsche Community     Comunidad en Español    English Community Русскоязычное Сообщество
    PepperonI blog 

  • I can no longer use the keyboard shortcuts, 'command  C' and 'command   V'.  Did I inadvertently do something to my keyboard or computer that caused this?  Is there a way to fix it?

    I can no longer use the keyboard shortcuts, 'command  C' and 'command   V'.  Did I inadvertently do something to my keyboard or computer that caused this?  Is there a way to fix it?

    You can also check in System Preferences > Keyboard > Keyboard Shortcuts, make sure that custom shortcuts were not created using those same commands. If ones were, they could be creating a conflict. Step throuogh each of the items in the left list, checking the array presented in the right pane for each.

  • Synaptics touchpad blocked & delay when using the keyboard in Windows 8.1

    Sometimes (possibly when I use the keyboard and then quickly attempt to move the mouse arrow on the screen with the Synaptics touchpad), I am unable to move the cursor for a half of second-or-so.
    Sometimes I cannot tap to click, maybe, few seconds (it is very annoying).
    There are some Mouse and touchpad settings in Windows 8.1 ("To prevent the cursor from accidentally moving while you type, change the delay before clicks work") which I set to "No Delay (always on)" but it does not work, either.
     I also checked the following registry key:
    HKEY_CURRENT_USER\Software\Microsoft\Windows\Curre​ntVersion\PrecisionTouchPad
    but "AAPThreshold" is set correctly to 0 (No delay).
    But I still experiences problems and touchpad does not work while typing and sometimes also few moments after.
    Using HP Zbook 14, Win 8.1 x64, Synaptics driver 17.0.18.23.

    Hi,
    If you trying connect two Universal apps through Bluetooth, can you check if the
    Windows 8.1 Bluetooth RFComm sample runs fine on both the devices? I successfully tested the Windows 8.1 Bluetooth RFComm sample on Laptop (Windows 8.1) and Windows Phone 8.1 (paired).
    Make sure the service which you are trying to advertise/listen is supported by both the devices. 
    -Sagar

  • How do I shut down from the login window in mountain lion using the keyboard

    how do I shut down/sleep/restart from the login window in mountain lion using the keyboard?

    Hi Thomas, thanks for your reply.
    Yes in standard start-up as it is and in recovery mode I still get the same message about Disk Utility being unable to repair the disk so I should back-up and restore.
    Some posters have said that booting into safe mode should unmount the installer and allow rebooting back into Lion, that would allow me to back-up the files properly, as my last back up was (as is often the way) not too recent.
    But I think your suggestion looks more likely to be he correct way to do it, and I'll take the hit on any data that I may lose.
    Thanks again.

  • Use the same form with different button turned on in different calls

    Can I use the same form with different buttons turned on in different calls?
    Thanks!

    This is to avoid piracy. What could happen is, people could buy music, and give it away for free online. Usually it is then you buy a complete album off iTunes that it will only be available on one device. It is tied to that account, and the device must be registered to that account to listen to it.

  • Opening LOVS using the keyboard

    I am trying to open a 9i LOV just using the keyboard. I have a text item with an LOV attached to it. When I tab to the item the new symbol appears (...). Is there a way of opening the LOV without clicking the mouse on this area?
    Many thanks.
    Mike

    Control-L while in the LOV field.

Maybe you are looking for

  • Unable to remove/change sales tax in sales order

    Hi Sappers!! I are unable to remove sales tax from a sales order.  I have tried to update the sales order by clicking on Header>Conditions Tab>Update-->Double click on G to redetermine the taxes. The sales order was entered the same day the Vertex re

  • How to launch factory image after format of hard drive

    I have an HP TouchSmart600 PC that had a nasty rootkit.  I've backed up the Factory Image partition, and then deleted all partitions and formatted the entire drive.  I will restore the Factory Image partition from backup.  NOW....  how do I access it

  • Problem with downloading the internal table onto the presentation server.

    Hey folks, I have a problem where in i am downloading one year of sales done by the company. I wrote a program to download the file onto the presentation server . The error occurs in the FM GUI_DOWNLOAD where if the file exceeds 105843504 bytes its g

  • How to remove underlining on text links in Muse...

    Hi, Anyone know how to remove the annoying underlining of text links in Muse. I have of course, styled my link to have no underline - which in Muse works, but doesn't once online. Even better - does anyone know how to create a hover style via Muse? I

  • JavaScript Error when adding the Server Behaviors for insert Record in php_mysql

    Hi guys, I am using Adobe DreamWeaver CS4. Here is the Scenerio, i am doing  php mysql driven website. While adding the server behavior for insert record i got following error Plz help me.. Thanks in Advance RafelNash