Why is my JTextArea working as a TableCellEditor?

Hello all,
I have implemented a CellEditor using a JTextArea as the editing component because I need to handle multiline contents.
So far everything works fine. I can start editing the contents by doublecklicking. And the input is accepted when I select a different cell in my table, the changes are discarded when I hit ESC.
After searching this forum and google for a while on this topic (because there are some problems I couldn't solve so far, see below) I am puzzled that it is working at all!
The basic layout of my component is, that I have a JTextPane inside a JScrollPane. My class implements the TableCellEditor interface.
getTableCellEditorComponent() returns the scroll pane
getCellEditorValue() returns the contents of the JTextArea
isCellEditable() checks for a doubleclick in case of a MouseEvent
otherwise returns true (stolen from DefaultCellEditor);
stopCellEditing() and cancelCellEditing() do nothing apart from notifying any listeners.
Interesting enough stopCellEditing() and cancelCellEditing() are never called even though editing works as expected. What am I missing here???
My expectation was that those methods are called when I leave the editing cell (stopCellEditing) or if I hit ESC (cancelCellEditing())
If they don't get called, why is the new value actually applied to my table model?
But I still have another problem which I cannot solve.
I'm trying to make this editor behave like the defaultCellEditor:
- start editing as soon as a key gets typed (if that cell has the focus). Somehow the editing is started but seems to end right away.
Same with hitting F2. I have the impression that the focus is set to the ScrollPane rather than to the TextArea because the component returned by getEditorCellComponent() is the ScrollPane. How can I change this? If I return the TextArea, it is not scrollable...
- Jump to the next cell when TAB is pressed. Currently the TAB character is inserted. I have tried overwriting isManagingFocus() on the editor component, the scroll pane and my editor itself, but to no avail.
- End the editing when the ENTER key is pressed (Ctrl-ENTER should insert a new line).
From all I read in this forum and the newsgroups, this should be handled by the ActionMap/InputMap, but I don't know which actions I should use to achieve this goal (i.e. which action makes the table stop the editing and move to the next column)
Any help is greatly appreciated!
Cheers
Thomas

Complicated little beast, is it?
To have control over the real editing that's taking place, you have to subclass JTextArea and override the processKeyBinding method.
Interesting enough stopCellEditing() and cancelCellEditing() are never called.You have to call these methods yourself when certain keys are detected in processKeyBinding
- start editing as soon as a key gets typed (if that cell has the focus).Override the processKeyBinding in JTable to have better control of the keytype event. If you detected a key that signal the start of editing, you must go thru the motion of setting up the editor, etc... just like JTable does. Then, as a final step, give focus to your edit component and dispatch the key type event to it (be careful because several events are fired by simply pressing a single character on the keybaord). This very last step may have to be put into SwingUtilities.invokeLater if you find that the event is fired before your editor is ready).
- Jump to the next cell when TAB is pressed.
- End the editing when the ENTER key is pressed (Ctrl-ENTER should insert a new line).Again, you can trap TAB, ENTER, Ctrl-ENTER in processKeyBinding and do whatever your heart desired.
Whew........... anyway, if you want to see a working model, check it out at the link shown below:
http://home.attbi.com/~aokabc/ABC/AOKabc.htm
;o)
V.V.

Similar Messages

  • Confused as to why this doesn't work...

    I wrote this code correctly, but it doesn't seem to work. I'm not sure if I'm leaving something out or not using something correctly. If anyone can tell me why this doesn't work, it would be greatly appreciated!
    P.S. in the actionPerformed method, I want to put the window to close once someone clicks an "ok" button. How is this done? I've tried using setDefaultCloseOperation(3), but it doesn't seem to work.
    peace,
    Mark
    //?2002 Copyright. MJA Technologies.  All Rights Reserved.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class About extends JFrame implements ActionListener
        JTextArea textarea;
        JPanel panel1;
        JButton okbutton;
        String output;
        public About()
            super("Pages");
            Container container = getContentPane();
            textarea = new JTextArea();
            textarea.setText("Pages 1.0 beta 0\n?2002 MJA Technologies.\nAll Rights Reserved.");
            container.add(textarea);
            setDefaultCloseOperation( 3);
            setVisible(true);
            setSize(400, 300);
        public void actionPerformed(ActionEvent event)
            if(event.getSource() == okbutton)

    Oh see, you said this:
    "P.S. in the actionPerformed method, I want to put the window to close once someone clicks an "ok" button. How is this done? I've tried using setDefaultCloseOperation(3), but it doesn't seem to work."
    so I said this:
    "setVisible(false)"
    NOOOOOOOOOOOW you say the TextArea doesn't show up...that's a whole other problem.
    Jeeeeeeeeeeeeeeeez.
    So what layout manager are you using in the container? (hint hint)

  • Why does GarageBand audio work for guest user but not my account?

    Hello, I have a 15-inch MacBook Pro (2.2 GHz Intel Core i7, 4GB 1333 MHz DDR3) from late 2011 that I bought brand new in 2012. I'm running OS X Mavericks 10.9.4 and my MacBook has 500 GB of storage.
    About a month or two ago I tried to download the new GarageBand (10.0.2) but I had trouble completing the loops download. The download would stop halfway through because of a network error. So last week I decided to try to download it again, and I was able to do so after reading some discussions about the issue. I successfully completed the download in safety mode and then I restarted my MacBook. At this point I was able to open GarageBand 10.0.2 and create a new project. Unfortunately, there was no audio coming through the output and sound bar for the various audio components in GarageBand. I had no audio when previewing the loops or playing it back in an audio track. I didn't really test anything else out because I figured I needed to fix this problem first. I have read many discussion boards about audio problems with GarageBand. I have already made sure everything is set properly in the GarageBand preferences and the audio preferences in system preferences. I've tried restarting GarageBand and restarting the computer.
    This evening I found a discussion from the username icewhatice and they seemed to have had my exact problem. I'm not sure that I found the answer on this discussion though. For reference, this is what icewhatice posted: "I have no audio coming from Garageband 10.0.2. Downloaded it on Saturday and have spent the last two days trying to figure out why it won't work. I'm using a macbook pro with an Alesis QX49. GB registers keyboard when I plug it in but no sound whatsoever, not even from the onscreen keyboard. It seems to read the keyboard as if I play a C chord, it appears in the display. I've done all the obvious stuff like check preferences, restart, I've deleted and downloaded new GB several times and always with same result. Actually, it took me about four attempts to download it in the first place as I was getting an internet connection error message right at the end of the download, and I see others have had that problem. Managed to solve that by downloading in safe mode but now the no sound thing is driving me absolutely crazy because I can't play my keyboard!!!!! Also, worth noting that there is no audio level being read anywhere, I believe in the new version this appears in the volume control at the top. I've also looked into it potentially being a problem with my keyboard and it possibly needing an update but can't find any difinitive answer for that anywhere. I've stopped looking into that because the on screen keyboard doesn't even work - if that worked then I would know at least GB works and it's something to do with the keyboard. So, I am at a complete loss. If anyone has any ideas about why this is happening or what I could do to solve then I would be very grateful."
    After reading this, I realized that I am unable to create new tracks, and I realized that I have the same problems with old projects saved from the last version of GarageBand I had. I have not tried to download GarageBand again since it did not work for icewhatice. léonie ended this post by saying: "Something is certainly wrong - either the current project, some settings in your user account, or the downloaded GarageBand version. Or incompatible software may be interfering. If a new project does not work, try to test by logging into a different user account, for example the "Guest User" account. Create a new project using this account. Does GarageBand work better from this account?  Then we will need to troubleshoot your preferences."
    I have tried this and started a new GarageBand project in the "Guest User" account. GarageBand was working fine in the "Guest User" account and all of the audio was working properly. Does anyone know how I should troubleshoot my preferences?

    If an application is working in a different account, but not in your regular account,try t find out, what you configured differently in your own account, for example start-up items or preference panes you are using, applications and other helper tools, that are only installed for your regular account. As a first guess, remove GarageBands preference files from the user library in your Home folder.
    But you will have to reset all settings you did in the GarageBand preferences dialog. And GarageBand will not remember the last project. You'll have to find the file manually.
    Remove these files from your User Library to a folder on your Desktop:
    ~/Library/Containers/com.apple.garageband10/
    ~/Library/Preferences/com.apple.garageband.plist
    ~/Library/Caches/garageband
    Quit GarageBand, then remove the files to a folder on the Desktop and restart the computer, before trying again to open GarageBand.
    You user library may still be hidden, as is the default in Mavericks: To open your hidden user library:
    Select the "Home" folder icon (the little house)  in the Finder's sidebar and press the key combination ⌘J to open the "view options".
    Enable "Show Library Folder".
    Then open the Home folder and open the Library folder inside and navigate to the Preferences, Caches, or Containers folder. Remove these folders completely - don't leave anything inside:  ~/Library/Containers/com.apple.garageband10/,
    ~/Library/Caches/garageband  .

  • Why does abode not work on my galaxy tab2

    Why does abode not work on my galaxy tab 2?

    The games dont load they just say I need to update to the latest version or say that it is not compaterble with it.

  • Why does sound not work on my Mac Air?

    Why does sound not work on my Mac Air --all setting seem okay. OSX 10.9.2 operating systyem.

    Open System Preferences > Sound > Output
    Make sure the coorect output devices is selected and the Mute button is not checked.

  • Why youtube dose not work on my macbook pro 10.6.6?

    why youtube dose not work on my macbook pro 10.6.6 ?

    Double check you have the latest version of Adobe Flash.

  • Why is it not working?

    So I went to get a app today, and I was told from someone that its better to do it when your phone is hooked up to your comp. So I did it through Itunes I click get app then agreed to Itunes on w.e there agreeing thing was saying I then went to sync my phone to get it and it said that this app was not installed on the iPhone "My name" cause you are not authorized for it on the computer. This is the computer I used to hook up this iphone (3g) and everything. Why isn't this working?

    O.k, this is my GravField class, now the error occurs when i try to call this in my main metod class, which i put up previously. I always compile to make sure everything works and it does in the GravField class, however when i call the method in my main method thats where the above error occurs. (Thanks for taking the time, really appreciate it!)
    public class GravField
      private final double M = 5.974E24;
      private final double R = 6380e3;
      private double Mass;
      private double Radius;
      public GravField()
        Mass = 1;
        Radius = 1;
        return;
      public GravField(double r, double m)
        Radius = r;
        Mass = m;
        return;
      public void setRadius(double r)
        Radius = r;
        return;
      public void setMass(double m)
        Mass = m;
        return;
      public double getMass()
        return Mass;
      public double getRadius()
        return Radius;
      public PhysicsVector Accel(PhysicsVector w) //w is position vector
         PhysicsVector g = new PhysicsVector();  // g = (0,0)     
         double G = 6.673E-11;
         double x = g.getX();
         double y = g.getY();
         double z = w.getX();
         double zz = w.getY();
         if(w.magnitude()>Radius*R) {
         x = (z*-G*M*Mass)/(w.magnitude()*R*Radius*R*Radius);
         y = (zz*-G*M*Mass)/(w.magnitude()*R*Radius*R*Radius); }
         else
         { x = (z*-G*M*Mass*Radius*R)/(w.magnitude()*R*Radius*R*Radius*R*Radius);
           y = (zz*-G*M*Mass*Radius*R)/(w.magnitude()*R*Radius*R*Radius*R*Radius);
         return g;
    }

  • Why does my itunes work in the guest account but not my administrator account?

    I have tried to reset, retry, restart, reinstall and restore itunes on my pc to figure out why it won't work on my administrator account yet it's fine if I sign into my guest account. It worked fine one day and the next, just didn't work.  I have Windows 8.1. Any ideas?
    Thank you,
    Simone

    Make sure that mouse keys aren't on. System Preferences > Universal Access > Mouse and Trackpad
    System Preferences > Language and Text > Make sure that U.S. is selected. If there are multiple languages selected there will be a flag in the menu bar and make sure that that is set to U.S..

  • Not sure why Message is not working on my ipad.

    Not sure why message is not work on my iPad. It works find on my iPhone.

    http://support.apple.com/kb/TS2755

  • I upgraded for Firefox 4 and now my simplePass identity protection (biometric scanner) on my laptop will not work. WHY? It still works with IE but I don't use IE.

    I upgraded for Firefox 4 and now my HP SimplePass Identity Protection (biometric scanner) on my laptop will not work. WHY? It still works with IE but I don't use IE. It worked with the previous Firefox version but now when I use the internet, it doesn't even acknowledge I have the scanner. When I run my finger over it, it opens the settings panel but does not allow use of the already saved information or allow new information to be entered. I need this corrected. Any suggestions?

    I asked this same question, and just received a response:
    "Thank you for contacting DigitalPersona. There will be no update releases
    for DigitalPersona Personal in the future. There will be no updates for
    Firefox 4 nor Internet Explorer 9. IF they work they work, if they do
    not work with DPPersonal, then you will have to decide to either keep
    DPPersonal and forgo Firefox 4 or IE 9, or vice versa. DigitalPersona
    is leaving the consumer market and is focusing on business applications.
    In fact, DigitalPersona Personal will not longer be supported after
    Mid-April of this year.
    We apologize for any inconvenience this might cause. Sincerely, Tech Team "
    In other words, there will be NO update.

  • Why has Siri stopped working on iPhone 4 after upgrading to IOS 5?

    Why has Siri stopped working on iPhone 4 after upgrading to IOS 5? I've tried the disable and reboot but continue to get the network error.

    Apple has not been forthcoming on the explanation. My Siri worked on my iphone4 (not 4s) immediately after upgrading to IOS5, but I take it they have redirected the servers that used to support Siri to only work with Iphone4s.
    It is one thing for apple to only bundle the improved Siri with IPhone 4S, or  for them to remove Siri from the Ap store.
    But it is another thing all together for apple to purchase a company, and then cease the service that many of us paid for.
    Attempts to contact apple at apple store and via email have been unhelpful.
    Apple Fan--

  • ITunes says my computer isn't authorized to play one song, but all the rest of them work. The song works on my iPad so why won't it work on my computer or my iPod?

    iTunes says my computer isn't authorized to play one of the songs I just downloaded, but all the rest of them work. That song works on my iPad so why won't it work on my computer or my iPod? It says my computer isn't authorized to play that song so I type in my password and it pops up with a menu saying my computer is already authorized and it skips to the next song. No matter what I do it won't play that song on my laptop or my iPod.

    Could be a Corrupt download of that song...
    If you live in a Region that allows re-downloading Music...
    Delete the Song(s) and re-download...
    See Here  >  Download Past Purchases
    http://support.apple.com/kb/HT2519
    If not... Contact iTunes Customer Service
    Apple  Support  iTunes Store  Contact Us

  • Why does Adobe sendnow work and the newest and greatest Adobe Send does not work?

    Why does Adobe sendnow work and the newest and greatest Adobe Send does not work? I wasted about 8 hours on trying to get Adobe Send to upload 269 files that amounted to 469MB. When it did not work I made a zip file and after a lot of wasted run time that did not work. The first situation gives little indication of when a file is loaded compared to Adobe SendNow. In both cases with Send it failed with a message like only the first 50 can be loaded. When I went and looked none of them had been loaded. With the zip file (I wanted to hide the individual files so they would not be counted) it appeared to work but very slowly and finally said it was done and I went and looked and it had done anything for oever 2 hours except a false "I'm runninng" indication.
    Thus, I took a chance with Adobe SendNow and it works great. It never gave me a limit on the amount of files nor on the size of the complete job. It shows me one file at a time when it has finished with the file uploading it. SendNow has never given me any problems.
    Why woiuld you want to change the program from SendNow to Send without the newest program being the best, fastest, user friendly program of the two? It just doesn't make sense to me. I suggest that Adobe keep SendNow working until Send is fixed. I would also suggest that SendNow and how it looks be kept, called Send, then modify Send one thing at a time until you get it to the point you need it to be for Acrobat. I have heard nothing good and now I have experienced it that Send is a piece of junk. I wasted most of my work day on giving Adobe the benefit of the doubt to find out I made a very bad decision to trust Adobe to make good decisions on the transfer of a function to another place .... both Adobe's responsibility.without making it painless for your customers that totally rely on you. Don't throw away customer confidence as it is very hard to get it back.

    Funny how you answer to "troll". (What's your handle on AT&T forums?)
    Yep! Verizon living up to it's contractual obligations by not releasing updates. Caveat emptor!
    I think there are some reasonable expectations here to keep customer's happy. When one carrier offers upgrades there is an expectation the same will happen across all the carriers. We have seen that except Big Red.
    Verizon could have said the update is in MS court months ago and stilled the voice of the disgruntled, or at least redirected it, but instead chose to be silent. Not for market share but for partial blame I think.
    We will have to agree to disagree since you only see Terms & Conditions and I, see customer satisfaction.

  • Why won't icloud work with windows vista anymore?

    why won't icloud work with windows vista anymore?

    I had to re-install after the newly released iTunes - for Vista it does work with iClud 2 - not 3. You can download from this site.

  • I have an older iMac 5,1 and the disc drive no longer works. I was hoping that I could the Apple USB super drive as a replacement, but the info on the super drive page says compatible with iMac 2012 or later. Does anyone know why it would not work for me?

    I have an older iMac 5,1 and the disc drive no longer works. I was hoping that I could the Apple USB super drive as a replacement, but the info on the super drive page says compatible with iMac 2012 or later. Does anyone know why it would not work for me?

    A reply to similar question (Q & As , in product page Apple Store) says:
    "...dissable the internal reader hardware from devices setup. Then plug the external usb superdrive and that's it."  Answered by Enrique T from Lima Oct  25 2013.
    If you can locate an external Apple USB 'Air" superdrive for earlier model MacBook Air, that should work. The newer one for the Air is the same as for iMac, now.
    You may be able to use other brands of external USB optical drive with your older intel-based iMac, as some of them function capably. A few should also be able to see system discs or other bootable utilities on DVD.
    Hopefully this helps.
    Good luck & happy computing!

Maybe you are looking for

  • OA framework sample Search Page

    hi all I have created EO,VO and AM for creating a page that search the records from a table. I can see the search page proper but i am having below error while searching the record.(when i click the "Go" button). oracle.apps.fnd.framework.OAException

  • UK iphone user - travel adapter advice needed

    Hi, We're heading off to Mexico shortly from the UK for a two week vacation. Since I intend to take my iPhone 3G with us for emergency use and to take advantage of the free wireless in the hotel (with data roaming switched off), I need some guidance

  • 72GB of free space missing...again.

    Ok, so I have been having this issue intermittently since iOS 7.0. I am now on 8.3 (just upgraded to it this morning) but the problem is still here. Basically, after a weekend of streaming a LOT of purchased videos to my iPad (not downloading them, m

  • PDF preview in windows 8.1

    I am facing a problem previewing PDF file from my application. It was working find in windows xp and windows 7 machines, but showing error line "Error HRESULT E_FAIL has been returned from a call to a COM component" in windows 8.1 machine. my applica

  • DI-Error: You cannot select batch or serial numbers for a closed row

    Hello Experts, I have several B1-Systems connected to R/3-Systems via B1iSN. In B1 for example I have 2 rows in Purchase Order. One row was closed by a goods receipt - 1 row is still open. From our R/3-System we send Order-Acknowledgements to B1. Bec