Sharing Document between TableEditor and JTextArea

hi,
i'm trying to share a javax.swing.text.Document between a TableCellEditor and a JTextArea, so that both, the textarea and the tableeditor show the same text, regardless of where the user is typing.
At the moment I'm doing this: every time the selection of the table changes, i get the document from the table editor and assign it to the textarea. This construct seems wo work, but only in one direction: if i type text into the table cell, the textarea gets updated, but not the other way round.
any idea, what could be wrong?
some code:
public void valueChanged(ListSelectionEvent e) {
    if(e.getValueIsAdjusting()) {
        int row = table.getSelectedRow();
        JTextComponent txtComp = (JTextComponent) table.getCellEditor(row, TRANSLATED_COL).getTableCellEditorComponent(table, "", true, row, TRANSLATED_COL);
        translatedTextArea.setDocument(txtComp.getDocument());
        showItem(row);
}

sorry for my late response. here is an example:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.Enumeration;
import java.util.Properties;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.JTextComponent;
public class TranslatorPanel extends JPanel implements TableModelListener, ListSelectionListener {
     public static final int ITEM_COL = 0;
     public static final int TRANSLATED_COL = 1;
    private JTable table;
    private DefaultTableModel model;
    private JTextArea translatedTextArea = new JTextArea();
    public TranslatorPanel() {
        initGUI();
    private void initGUI() {
        model = new DefaultTableModel(new Object[][] {}, new String[] {"Key","Value"});
        model.addTableModelListener(this);
        table = new JTable(model) {
             public boolean isCellEditable(int row, int col) {
                  return col == TRANSLATED_COL;
        table.setSurrendersFocusOnKeystroke(true);
        table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        table.getSelectionModel().addListSelectionListener(this);
        setLayout(new BorderLayout());
        add(new JScrollPane(table), BorderLayout.CENTER);
        add(new JScrollPane(translatedTextArea), BorderLayout.SOUTH);
        setSize(800,600);
        translatedTextArea.setPreferredSize(new Dimension(800, 300));
        TranslationItem item = new TranslationItem("key1");
        item.setTranslations("value1", "en");
        model.addRow(new Object[] {item, item.getTranslation("en")});
        item = new TranslationItem("key2");
        item.setTranslations("value2", "en");
        model.addRow(new Object[] {item, item.getTranslation("en")});
        item = new TranslationItem("key3");
        item.setTranslations("value3", "en");
        model.addRow(new Object[] {item, item.getTranslation("en")});
    // called, if the content of the table has changed
     public void tableChanged(TableModelEvent e) {
        int row = e.getLastRow();
        if (e.getType() == TableModelEvent.UPDATE) {
             // store the new value in the item
             TranslationItem item = (TranslationItem) model.getValueAt(row, ITEM_COL);
             item.setTranslations((String)model.getValueAt(row, TRANSLATED_COL), "en");
     // called if selection of the table changes
     public void valueChanged(ListSelectionEvent e) {
          if(e.getValueIsAdjusting()) {
               int row = table.getSelectedRow();
               JTextComponent txtComp = (JTextComponent) table.getCellEditor(row, TRANSLATED_COL).getTableCellEditorComponent(table, "", true, row, TRANSLATED_COL);
               translatedTextArea.setDocument(txtComp.getDocument());
               showItem(row);
     private void showItem(int row) {
          TranslationItem item = (TranslationItem) model.getValueAt(row, ITEM_COL);
          translatedTextArea.setText(item.getTranslation("en"));
    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setSize(800,600);
        frame.add(new TranslatorPanel());
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    private class TranslationItem implements Comparable {
        private String key = null;
        private Properties translations = new Properties();
        public TranslationItem(String key) {
            this.key = key;
        public String getKey() {
            return key;
        public void setKey(String key) {
            this.key = key;
        public String getTranslation(String locale) {
            String value = translations.getProperty(locale);
            return value == null ? "" : value;
        public boolean translatedForLocale(String locale) {
            String translation = getTranslation(locale);
            if(translation == null || translation.length() <= 0) {
                return false;
            } else {
                return true;
        public void setTranslations(String translation, String locale) {
            translations.setProperty(locale, translation);
        public String toString() {
            return key;
        public void print() {
            System.out.println("key " + key);
            Enumeration en = translations.propertyNames();
            while (en.hasMoreElements()) {
                String locale = (String) en.nextElement();
                String translation = translations.getProperty(locale);
                System.out.println("\t"+locale+" = " + translation);
        public int compareTo(Object o) {
            if(o instanceof TranslationItem) {
                TranslationItem ti = (TranslationItem) o;
                return ti.getKey().compareTo(getKey());
            return 0;
}

Similar Messages

  • Sharing files between users and macs

    My husband and I share an iMac. I have a MBA for traveling and my husband a PC laptop (though he rarely uses for private stuff). We both have iPhones.
    We are looking for a way to:
    - Share our photos (we don't use iPhoto) and some files. We would like to have this in one shared folder, that we can access from both accounts in the iMac, the MBA and ideally (though not a must) the PC and iPhones. We would both need to have admin rights to edit documents, etc.
    - Have access to all the information in my account on the iMac from the MBA. Ideally, same thing for his and the PC.
    - Have access to all the data remotely when traveling.
    - Have all the data backed up locally (we already have a cloud backup, but we'd like to have a local backup too as it's easier and quicker to access)
    We have read a lot about configuration, NAS, time capsule... but we get more and more confused, as we are obviously no tech experts.
    Dropbox is not our preferred choice. We already have a cloud backup system. We'd rather have the files stored and accessed locally for everyday use.
    Using a NAS to store shared folders and backup the rest sounds good, but they either seem very complicated to set up, or they have mixed reviews in terms of stability, especially to access files remotely.
    Timecapsule seems easier and more straightforward, but I'm not sure it would solve the "sharing files between users and macs with admin rights"? It seems to be more focused on backing up the main drive and then providing access to the backed up files. (Though I might be completely mistaken!)
    We just can't manage to have one shared folder between both accounts in the iMac. We need to grant admin rights document by document. We don't manage to make it work automatically so we both have one folder to access with full rights for all the contents inside it. And this seems to me like something that should easily be done...?
    Any help, advice, proposals... would be greatly appreciated!!!

    Move any file you want to the other user to access to the Shared Folder. Anything you put in that folder is available to all users.
    The shared folder is here:
    Macintosh HD > Users > Shared

  • How to create shared folder between mac and windows

    how to create shared folder between mac and windows

    Us ean external drive formatted FAT32 or ExFat. Both OSx and Windows can read/write to the drive and both can use the same data files as long as you have a program that can open and save these files. For example, Word running both on OSx and on Windows will be able to work with the same document on the external drive.

  • Hello there - how can I share my iTunes library between two users on the same computer? I put the library in a shared folder between both and have selected this library on both as well, but when I update iTunes with music etc it only appears on one?

    Hello there - how can I share my iTunes library between two users on the same computer? I put the library in a shared folder between both and have selected this library on both as well, but when I update iTunes with music etc it only appears on one?

    Thank you Joe - I tried this but it's only showing a teensy amount of music - the stuff on the second users account as opposed to the giagntic library on the 'main' account. I actually went to a Genius Bar and they said that apple doesn't really want you to share music between accounts - parents don't want to hear their kids music etc. Which seemed strange, but it might be the case sadly   Thanks anyway!

  • Sharing keywords between LR and PSE 9 Organiser? :-(

    OK, I've owned 3 photo products from Adobe (Photoshop Album, Lightroom and Photoshop Essentials) and have 3 keyword file formats! I use LR as my main photo organiser and have started using PSE and its Organiser but am frustrated by the lack of coherent design of keyword files. I have hundreds of keywords in LR. I had to write some Python code to convert my "Album" keywords to the LR format and it seems I have to do the same to get keywords from LR into PSE's organiser. But there's now a new problem...
    Unfortunately when I import keywords into PSE's Organiser any duplication of existing keywords results in duplication in the keyword list - i.e. when I add "From file.." PSE adds to the list rather than merging! PSE is clearly not designed to re-load keywords from file any extend the keywords. If I export all my keywords and re-import them I don't expect the number of keywords to double! Oh - I can;t delete keywords before importing because I'm told everything it's 'learned' (people etc. will be lost).  Keywords appear to be exportable but not importable.
    I clearly cannot import keywords into PSE's organiser as I can with LR.
    Is anyone sharing keywords between LR and PSE's Organiser?

    Thanks, I can see how that can work and the problems. It looks like the keywords themselves cannot be easily shared and I agree that having two organising programs is problematic but I wanted to 'export' the keywords I have created including their structure from Lightroom and import them into PSE organiser. You'd think you could do this with two similar products from the same company. The organisers in question are used for two purposes and the photos in each are different - i.e. I use lightroom for my pro stuff and PSE for family/casual stuff and no photo would be present in both. It looks like PSE really isn't designed to import keywords. I have Python code to create a PSE keyword file from a lightroom file so that will have to do as it's clear there's no interoperability.
    Thanks for your suggestions.

  • Hi, I need to import contacts from windows outlook to MAC outlook. I need the field mapping document between windows and mac outlook.

    Hi, I need to import contacts from windows outlook to MAC outlook. I need the field mapping document between windows and mac outlook.

    Then I suggest you post your question the Microsoft Mac forums since it's their products you're having trouble with
    http://answers.microsoft.com/en-us/mac

  • Problem setting up shared printer between PC and Mac with 10.6

    I am trying to setup a shared printer between my Mac and PC. I have a HP K80 attached to my PC (which has Vista Home Premium). I have a Macbook pro with 10.6. I have shared the printer on the PC side. From the Mac I have added the printer via Windows Printer sharing, but for some reason I cannot print to the printer. Everytime I try to print, the job just pauses. Is there something I am doing wrong?

    Thanks I installed the gutenprint drivers and tried this, and now all working:
    http://guides.macrumors.com/Printingto_a_Shared_PCPrinter
    Printing to a Shared PC Printer
    This article describes how to print from Mac OS X to a shared printer connected to a Windows XP machine. It assumes the computers are already networked and that you can access the PC's files. These instructions are relevant for Mac OS X 10.2 upwards. The instructions may work with Vista. I don't have the means to try it.
    1. Find the IP address of your PC - go on Start > Run. Type in cmd and click run. Now type in ipconfig /all and hit enter. This should give you the machine's IP address.
    2. Share the printer. Open up Printers and find the one you want to share. Right-click and choose Share. Now click the 'Share this printer' radio button. Now choose a sharing name. Keep it simple - e.g. HP, Office, PC etc.
    3. Open a web browser on your Mac and type localhost:631 in the address bar
    4. You should now have the Common UNIX Printing System web interface up. Click the 'Add Printer' link.
    5. Type a name for the printer, making sure you don't include /, # or space characters. Click continue.
    6. Select Windows Printer via SAMBA from the Device list and click continue.
    7. For the URI, you need to include a username and password for an account on your PC. You then need to enter a URI in the following format: smb://username:password@ipaddress/printer. So for example smb://johndoe:[email protected]/HP
    8. Choose your printer's make, or if you have a PPD file for the printer, choose that. Click continue and choose your printer's model. Now click Add Printer.
    9. Done! You now have a list of options for changing the various properties of the printer.
    You don't need to be on the same workgroup or domain as your PC, just the same subnet. If both your Mac and PC are connected to the same router, either wired or wirelessly, then you should be on the same subnet.
    Thanks guys

  • Different document between KZ and RE

    I would like to know what is the different between document of KZ and RE, as I know, RE is created by MIRO. how about KZ. Thanks

    Hi Port,
    RE Document type is for Vendor Purchase Invoice booking time Financial side automatically genarated the document at the the time of MIRO Entry against the WE Docuement Entry.
    KZ Document type is for Vendor Payment through Check or others.
    Hope it will clear.
    Regards,
    Kishore K

  • Home Sharing feature between Macs and PCs?

    Can I use the new Home Sharing between Macs and PCs?

    Yes, I do. The only bug I've found is this:
    My XP machine will not play video from the Mac.

  • Sharing bookmarks between macbook and a toshiba pc

    how do share my bookmarks from my Macbook Pro and a P.C. ?

    See if one of the following articles will help guide you in the right direction:
    o Sharing files between a Windows XP PC and a Mac running OS 10.4.x
    o How Do I Network My Mac and PC?

  • Comparision Document between PI and Informatica.

    Hi All,
            I have requirement where the current Informatica system is being replaced by PI. I would like to present .PPT to my client showing the comparison of operations between PI and Informatica. I would like to show pros and cons of both PI and Informatica. Request to provide me any useful document mentioning so.

    Hi,
    Please check below link.
    SAP PI 7.1 in what way it can replace an ETL tool like Informatica?
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/10fbac70-c381-2d10-afbe-c3902a694eaf?quicklink=index&overridelayout=true
    In addition you can refer below link as well
    Re: SAP PI 7.1 or 7.3 vs webMethods,Oracle Fusion,Biz talk, Tibco,IBM websphere
    Regards,
    Deepak.

  • Sync documents between laptop and flashdrive

    Hello all...
    When I was using Windows, I used to use Briefcase to sync documents between my flash drive and my laptop; I later found SyncToy to be quite useful and a lot more reliable.
    Is there any program (like SyncToy or Briefcase) that will allow me to keep fully-editable copies of the same document on my flash drive and notebook, and sync between them on my Mac?
    Thanks!
    JG
    Message was edited by: Juan Guapo

    Take your Pick

  • Sharing calendars between 2010 and 2013

    Is there an incompatibility issue when sharing calendars from Office 2010 and Office 2013?

    Hi Dave,
    I'm not quite sure what kind of incompatibility issue you mean here. But as far as I know, there is not so much difference with the Calendar function between Outlook 2010 and Outlook 2013.
    Calendars that shared from Outlook 2010 should work well in Outlook 2013 and vice versa.
    If you have any specific issues regarding sharing calendars between Outlook 2010 and Outlook 2013, please feel free to post a question in our forum, we'll be happy to help you with it.
    Regards,
    Ethan Hua
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • Sharing Files between Mac and Windows XP PC

    I have an small office with three computers. There is a new Mac that basically acts as the server. There is a shared folder on the computer. The other 2 computers are PCs. All permissions have been set on the Mac. The other 2 users are set as Administrators on the Mac and have the ability to Read and Write. The other 2 users can access the files, but they are not able to make any changes. The shared folder has may sub folders. Any ideas?

    huh, i used migration assistant to create a user with all my old data. now i have 2 users. anyway, i was putting the old data i wanted (i plan to wipe out the old user) into the shared folder...and it was working fine. all of a sudden, i put files into the shared folder, and when i log in as the new user, i can't use the file. won't give me access.
    i've enabled file sharing, the files and folders are marked as shared, and well...it seems like file sharing is broken.
    ...ideas?

  • Sharing photos between iphone and ipad2

    i wondering how to share photos between ipad2 and iphone4

    you will need to set up an icloud account on both devices and then enable photo stream.
    Icloud: photo stream FAQ  http:///support.apple.com/kb/HT4486

Maybe you are looking for

  • Variable screen/variant screen authorization issue

    HI All, We have implemented standard Cost Center Overview Report(0SR_C02_Q0002) in BI 7. We have three selection fields: 1.Company Code which is mandatory 2.My controlling Area which is also mandatory 3.Costcenter which is not mandatory The requireme

  • Error please help!!! Internal failure error no.:0x80040707

    I only just got an ipod nano and when i put the disc given with the ipod on the computer this comes up: Internal failure Error Number : 0x80040707 Description: Then this comes up: Ipod for windows 2005-09-23 Access is denied Some one help please!!

  • Can't delete iPhone Picture folders!?

    I went from a 3gs to a 4s. Well when I had my 3GS I would plug it into my computer and go to My Computer, I would then click on my Iphone under Portable Devices, and it brings me to the DCIM folder for my pictures. Well when It was on my 3GS it was j

  • Video Snapshot shortcut on iChat.

    Hi! I was wondering if anyone could tell me what that weird symbol is in front of the keyboard shortcut when you wanna take a snapshot when you're video chatting on iChat. I can't find it on my keyboard... haha.

  • What does updating delete folders on iphone?

    Why is it that every time I plug in for an update, the update deletes all my file folders? I stopped using them rather than recreating them with every update. Thanks!