Why Component do not invoke KeyListener,when it is a CellEditor in JTable?

when I edit at a cell ,the JTextField do not invoke keylilsten,why?
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.text.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.util.EventObject;
public class Test extends JFrame {
     public JTable table;
     public JScrollPane scrollpane;
     public Test() {
          JTextField editor;          
          this.table = new JTable(5,5);
          this.scrollpane=new JScrollPane(table);
          for (int i=0;i<5;i++) {
               editor=new JTextField();
               editor.setBackground(Color.blue);
               editor.setForeground(Color.white);
               editor.addKeyListener(new kl());  //addkeylistener
               this.table.getColumnModel().getColumn(i).setCellEditor(new DefaultCellEditor(editor));
          this.getContentPane().add(this.scrollpane);
          this.scrollpane.setVisible(true);
          this.setSize(300,300);
          this.setVisible(true);
       public static void main(String args[]){
            Test test=new Test();
//KeyListener
class kl implements KeyListener {
     public void keyReleased(KeyEvent e) {
          System.out.println("keyReleased...");
     public void keyPressed(KeyEvent e) {
          System.out.println("keyPressed...");
     public void keyTyped(KeyEvent e){
          System.out.println("keytype...");          
}

I changed your code a bit to show you what you were doing wrong, you need to implement KeyListener:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.text.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.util.EventObject;
public class Test extends JFrame implements KeyListener {
public JTable table;
public JScrollPane scrollpane;
public Test() {
JTextField editor;
this.table = new JTable(5,5);
this.scrollpane=new JScrollPane(table);
for (int i=0;i<5;i++) {
editor=new JTextField();
editor.setBackground(Color.blue);
editor.setForeground(Color.white);
editor.addKeyListener( this ); //addkeylistener
this.table.getColumnModel().getColumn(i).setCellEditor(new DefaultCellEditor(editor));
this.getContentPane().add(this.scrollpane);
this.scrollpane.setVisible(true);
this.setSize(300,300);
this.setVisible(true);
public static void main(String args[]){
Test test=new Test();
public void keyReleased(KeyEvent e) {
System.out.println("keyReleased...");
public void keyPressed(KeyEvent e) {
System.out.println("keyPressed...");
public void keyTyped(KeyEvent e){
System.out.println("keytype...");

Similar Messages

  • Put movies in itunes on one computer why does it not show up when i access itunes from other computers or ipad2?

    put movies in itunes on one computer why does it not show up when i access itunes from other computers or ipad2?

    i just purchased a file that had videos in it. i put them in the itunes library on my pc where i first downloaded them. i was able to transfer them to my other pc, a laptop, through my home network. i am now trying to get them on my mac pro desktop and my ipad2. my mac pro can see the other computers on my home network but i cannot get it to connect to them. i know the operating systems are different but was hoping i could transfer pictures and files from pc to mac this way. haven't been able to get it to work yet. the videos i am trying to get my mac to see came in a folder with both mac and pc versions. i thought if i got the videos i purchased into itunes that i would then be able to get them to my mac pro and my ipad2. i am new to mac/apple and have always been pc-centric so trying to marry it all has been difficult. i speak pc pretty well but am just learning apple. am i trying to do things that are not possible? i sure could use a knowledgable friendly soul to walk me through my issues of having pc and mac on the same network. i have been able to get all computers and ipad to print on my network. thanks.

  • Why can I not open pictures when I click on the host icon on my desktop? It just sits there, and can not open from top menu bar as well, only via itunes

    why can I not open pictures when I click on the host icon on my desktop? It just sits there, and can not open from top menu bar as well, only via itunes

    Does your question involve iPhoto in some way?

  • HT1848 How do I sync my music on my computer to my iPhone - why does this not happen automatically when I connect?

    How do I sync my music on my computer to my iPhone - why does this not happen automatically when I connect?

    Do you have iTunes set to sync music to the device?
    Have you read the User's Guide that explains how to use the device?
    Syncing media and content to iDevices

  • Why can i not call out when in roaming but can recieve calls

    why can i not call out when roaming and my data shuts off but i can recieve calls

        rhondahuffman1,
    These are great question and we definitely want to help out! For starters, what model of device are we working with? Are you roaming outside of the country or is the device stating roaming within certain areas? What's your zip code? Happening in specific locations? Share some details, so that we may assist.
    AdamG_VZW
    Follow us on Twitter @VZWSupport

  • Why does Illustrator not remember filepaths when saving ??

    Hi,
    I'm finding it really frustrating that Illustrator 10 (on iMac G5 OS 10.3.9) does not remember filepaths when saving.
    Perhaps I've overlooked a setting somewhere.
    Does anyone know how I can rectify so Illustrator defaults to the last used filepath (as does almost every other program on earth) ??
    I'd be very grateful for any help.
    Thanks in advance.

    Can anyone tell me why this is happening?  Am I not saving this correctly?
    Well, to what format are you saving? The native AI format should always retain layers. Other formats such as EPS or older PDF Levels may indeed enforce flattening. also make sure you are not confusing layers with groups/ objects. There's a crucial difference between the two.
    And even more important, is there any way of restoring the different layers once this has happened?
    Well, you can manually add new layers and drag&drop your objects and groups into the new layers in the layers panel, but if you save it again to the wrong file format, that is wasted effort, so for the life of it make sure you get that figured out first.
    Mylenium

  • HT2648 I want to Repair Disk Permissions, but I do not have disk utility 10.4.3 on my Mac os X. How do I download it? Why did I not get it when I purchased the computer 2 years ago?

    I am having frequent pop-up boxes. It is very annoying. It was suggested that I repair permissions, but when I try, my 2 year old computer. with OSX operating systems has an old desk utility, and I cannot use it. How do I acquire disk utility 10.4.3?

    Any reason why you have not updated to the final version 10.4.11 of Tiger?
    General advice on updating Tiger:
    It is worth noting that it is an extreme rarity for updates to cause upsets to your system, as they have all been extensively beta-tested, but they may well reveal pre-existing ones, particularly those of which you may have been unaware. If you are actually aware of any glitches, make sure they are fixed before proceeding further.
    So before you do anything else:
    If you can, make a full backup first to an external hard disk. Ideally you should always have a bootable clone of your system that enables you to revert to the previous pre-update state.
    Turn off sleep mode for both screen and hard disk.
    Disconnect all peripherals except your keyboard and mouse.
    1. Repair Permissions (in Disk Utility)
    2. Verify the state of your hard disk using Disk Utility. If any faults are reported, restart from your install disk (holding down the C key), go to Disk Utility, and repair your startup disk. Restart again to get back to your startup disk.
    At least you can now be reasonably certain that your system does not contain any obvious faults that might cause an update/upgrade to fail.
    3. Download the correct version of the COMBO update from the Apple download site. If your car runs on gasoline you would not want to fill the tank with diesel, so don’t try to install the PPC updater on an Intel Mac!
    The 10.4.11 Combo Updater for PPC Macs is here:  http://support.apple.com/kb/DL170
    And for Intel Macs here:  http://support.apple.com/kb/DL172
    If you prefer to download updates via Software Update in the Apple menu (which would ensure that the correct version for your Mac was being downloaded), it is not recommended to allow SU to install major (or even minor) updates automatically. Set Software Update to just download the updater without immediately installing it. There is always the possibility that the combined download and install (which can be a lengthy process) might be interrupted by a power outage or your cat walking across the keyboard, and an interrupted install will almost certainly cause havoc. Once it is downloaded, you can install at a time that suits you. You should make a backup copy of the updater on a CD in case you ever need a reinstall.
    Full details about the 10.4.11 update here:  http://support.apple.com/kb/TA24901?viewlocale=en_US
    More information on using Software Updater here:
    http://support.apple.com/kb/TA24901?viewlocale=en_US
    Using the Combo updater ensures that all system files changed since the original 10.4.0 are included, and any that may have been missed out or subsequently damaged will be repaired. The Delta updater, although a temptingly smaller download, only takes you from the previous version to the new one, i.e. for example from 10.4.10 to 10.4.11. Software Update will generally download the Delta updater only. The preferable Combo updater needs to be downloaded from Apple's download site.
    Now proceed as follows:
    4. Close all applications and turn off energy saving and screensaver.
    5. Unplug all peripherals except your keyboard and mouse.
    6. Install the update/upgrade. Do not under any circumstances interrupt this procedure. Do not do anything else on your computer while it is installing. Be patient.
    7. When it ask for a restart to complete the installation, click restart. This can take longer than normal, there are probably thousands of files to overwrite and place in the correct location. Do nothing while this is going on.
    8. Once your Mac is awake, repair permissions again, and you should be good to go!
    If your Mac seems slightly sluggish or ‘different’, perform a second restart. It can’t hurt and is sometimes efficacious!
    9. Open a few of your most used applications and check that all is OK. In this connection please remember that not all manufacturers of third party applications and plug-ins, add-ons, haxies etc, will have had time to do any necessary rewrites to their software to make them compliant with the latest version of your operating system. Give them a weeks or two while you regularly check their websites for updates. This applies particularly to plug-ins for Safari 3.
    N.B. Do not attempt to install two different updates at the same time as each may have different routines and requirements. Follow the above recommendations for each update in turn.
    Lastly, Apple's own article on the subject of Software Update may also be useful reading:
    http://docs.info.apple.com/article.html?artnum=106695
    [b]If you are updating Safari (or just have):[/b]
    Input Managers from third parties can do as much harm as good. They use a security loophole to reach right into your applications' code and change that code as the application starts up.  If you have installed an OS update and Safari is crashing, the very [i]first[/i] thing to do is clear out your InputManagers folders (both in your own Library and in the top-level /Library), log out and log back in, and try again.
    So, disable all third party add-ons before updating Safari, as they may not have been updated yet for the new version. Add them back one by one. If something goes awry, remove it again and check on the software manufacturer's website for news of an update to match your version of Safari. Remember: Tiger up to 10.4.10 used Safari 2.0.4 or, if you downloaded it, Safari 3.0.3 beta. Safari 10.4.11 used Safari 3.0.4 which was [i]not[/i] a beta. If Safari 3.1.2 on 10.4.11 is not the fastest browser you have ever used, then something is wrong!
    Moreover, trying to revert to Safari 3.0.4 (or worse still, version 2) when running 10.4.11 or 10.5 can have repercussions, as Safari 3.1.1 uses a completely different webkit on which other applications like iChat, Mail and Dashboard Widgets etc also rely, and may entail you having to reinstall an earlier operating system.
    [b][i]Most errors reported here after an update are due to an unrepaired or undetected inherent fault in the system, and/or a third party ad-on.[/b][/i] Two such add-on that have been frequently mentioned here for causing such problems are Piclens and Pithhelmet. If you have them, trash them.
    Additional tips on software installation here:
    http://docs.info.apple.com/article.html?artnum=106692
    To reiterate, Input Managers reach right into an application and alter its code. This puts the behavior of the affected application outside the control and responsibility of its developers: a recipe for  problems. That's not to say that issues absolutely will ensue as a result of Input Managers, but you, as a user, must decide. If the functionality of a specific Input Manager or set thereof is really important to you, you may well choose to assume the associated risk.
    Again, the advice is to remove all Input Managers from the following directories:
    /Library/InputManagers
    ~/Library/InputManagers
    especially prior to system updates (they can always be added back one-by-one later).

  • Why can I not deauthorize computers when I want to, rather when big brother apple lets me?

    I know big borther apple wants to control my music, but why? I have either forgotten to deauthorize some old computers I got rid of, or had to re-format the ones I own. So why does big brother apple control when I can and cannot deauthorize my computers?

    What are you talking about?
    You can deauthhorize wheneever you like, however, you can only deauthorize all once per year.
    If you need more than that then contact itunes support and ask.
    No need to be so over dramatic.

  • Why iPad does not charge battery when is connected to my laptop?

    why ipad does not charge battery ehen is connected/sync to my laptop?

    Because most USB ports do not put out enough power to meet the iPad's minimum requirements. An iPad is best charged plugged into the wall with the supplied charger.

  • Why is iMovie not free but when i first got my phone it was?

    At first when i got my iphone i saw that ALL apple apps were free.  Now that i have had my phone for 2 months, i see that ALL apple apps are not free.  Does anyone know why the apps are not free when they were free when i first got my phone?  (I have an iphone 5s that is 2 months old)

    Go to Settings/General/About tap on Name, and change it.

  • HT4979 why can I not send email when away from my home wifi? Am able to receive messages OK, and outgoing mailserver is correct?

    Why am I unable to send email when away from my home wifi ? I am able to receive mail OK, and have double- checked the outgoing server which is correct. This problem is consistent with my Macbook Pro, iPhone, and iPad2.
    Attempts to send messages results in them sitting in the Outbox and never- ending 'sending message' displayed.
    I am able to send using my   me.com  server.
    Home service provider is Cogeco.
    Any help would be appreciated.

    iOS: Unable to send or receive email
    http://support.apple.com/kb/TS3899
    Can’t Send Emails on iPad – Troubleshooting Steps
    http://ipadhelp.com/ipad-help/ipad-cant-send-emails-troubleshooting-steps/
    iPad Mail
    http://www.apple.com/support/ipad/mail/
    Try a Reset - iPad How-Tos  http://ipod.about.com/lr/ipad_how-tos/903396/1/
    Or this - Delete the account in Mail and then set it up again.
     Cheers, Tom

  • Why is FmsDestroyFileAdaptor not being called when FMSCore exits

    I'm developing a file-io plug-in and the FmsDestroyFileAdaptor or FmsDestroyFileAdaptor2 functions are not being called for my dll when the FMSCore process exits. I built the and tested the sample plug-in that comes with FMIS 3.5 and the same problem exists with it as well.
    Any clues? Is this a bug?
    Thanks,
    George

    This issue has been fixed in 3.5.2 release. See http://www.adobe.com/support/documentation/en/flashmediaserver/releasenotes.html

  • Why is "run" not a choice when installing itunes?

    I just tried to download itunes for the first time. "Run" was not an option, so I chose "save". I have tried again to download it, and the same thing happens. I cannot find itunes on my computer when I search the programs or when I plug in my ipod. Any suggestions?

    You need to look for iTunesSetup.exe. If you can't find it on your system, most likely it's not getting downloaded completely. Check to see where your browser is saying that it's saving the file - it may be defaulting to a temp folder which may be getting cleared. If so, change to someplace more permanent; your user's desktop, Documents folder, etc. If all else fails, try a different web browser.

  • Why ComboBox.disabledForeground not take effect when JComboBox is editable

    Hi, there:
    I use UIManager.getDefaults().put("ComboBox.disabledForeground", Color.GRAY ) to define the fore ground color when my JComboBox is disabled. However, just noticed that if I set JComboBox Editable to be true, then, the application seems using the default disabledForeground color instead of the one I defined (ex. gray).
    For example:
    UIManager.getDefaults().put("ComboBox.disabledForeground", Color.gray );
    comboBox.setSelectedItem("bbbbbb");
    //comboBox.setEditable(true);
    comboBox.setEnabled(false);The above code works fine and set foregound color as gray. However, if I added the line: comboBox.setEditable(true); The application just uses default foreground color (light blue in 1.5).
    Does any one know why?
    Highly appreciated if any comments or hints.
    Thanks a lot in advance.
    David

    problem doesn't exist. close it.

  • Why I do not see words when receive an Email containing graphics?

    This happens only when open Emails with Firefox 7.0.
    No problem with Internet Explorer.
    When open Email with Firefox, I can only see the graphic part, but can not see the words that follow the graphic.

    Not sure I understand your question but here goes, Go to Settings, then Accounts, then click the Add New Account Icon on the bottom, then Email, then on the bottom of the screen click on the Advanced idon (looks like 2 plugs), from there you can choose the type of email account which for SBC is probably POP and fillin all the specific fields. If you get all the settings correct you should be in business.

Maybe you are looking for

  • File Vault decryption problem

    Hi guys, I'm running 2013 2.6GHz i5 13' MBP on 10.9 I have trouble unlocking my 2TB WD external drive. I have encrypted it with disk utilities when i formated it 4 months ago. Everything worked fine up to this moment. I cannot unlock it, but my paswo

  • Help!!  No photos showing up in iPhoto library - Pt. 2

    I'm having the same exact problem. Yesterday, I was viewing my photos and nothing was wrong. Today, nothing shows up in the application. Not one pic! <Post Relocated and Edited by Moderator>

  • Showing navigation attributes in the same column of a query

    Hi, I would like to know if there is a way to define a query such that TWO navigation attributes that reference the same underlying characteristic can be displayed in the SAME column rather than TWO separate columns. I will describe an example scenar

  • IDES information

    Hi all, I am a newbie here, hope there is someone in this forum that can help me with my queries below. 1. Just installed IDES 4.7SR1. Just wonder whether any application data included in the IDES because I did not see any data in client 000 and clie

  • Reinstalling the Final Cut Studio media only?

    Hello everyone, I have the retail version of FCS2 and during the installation I told the installer to copy all of the extra media and templates for Soundtrack, Motion, etc. to an external hard disk. All was fine until the external disk crashed. My qu