Using the swing clipboard and DefaultEditorKit.copytAction

Hi all
Ive heard that i can use the swing DefaultEditorKit to basically copy and paste text throughout my application (like using Ctrl+C ctrl+V)
basically i have a number of elements such as textpanes and edit boxes and i want to be able to copy and paste text between them with the least amount of effort, most examples i have seen about implementing copy and paste require you to specify the elements that you need to copy and paste from
i dont want to have to specify every element, i just want a simple action that says copy the selected text, and paste the selected text (dont have to worry about cut really)
Ctrl+C and Ctrl+V both do this natrually, but how do i call a simple method that does the same thing that the keystrokes do.
I just want two menu items that when i invoke their click listeenrs to say something like
copylistener{
copy();
Ive seen a few examples of the swing methods but these also seem to need to invoke actions on the elements that you want to copy and paste between, but the keystroke dont need any of this

Sorry, I see your confusion now.
Yes, you need a few helper methods to get the actual Action, but you don't need to do this for every text component because the Action is shared by all text components.
Text components use an EditorKit. The editor kit provides support for basic functionality of each text component. (ie. cursor movement, text selection, cut, copy, paste...). The EditorKit uses Actions to implement the basic support. Each Action extends TextAction which contains a method "getFocusedComponent" which returns the last text component that currently has focus. (clicking on a menu item is only a temporary loss of focus).
So the code in the TextComponentDemo is being very efficient and is reusing the static Action that was created by the DefaultEditorKit. So even though your form may have multiple text components, you only need to create your menu item once using any text component.
If you don't want your code to reuse the existing Actions, you can create your own Action directly from the EditorKit. Then this Action can be used to create a JMenuItem or JButton. Here is a simple example of using this approach:
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=302962

Similar Messages

  • Java applet using the Swing API

    write a Java applet using the Swing API to manage a PC repair shop. When a PC is brought in for repair, a member of staff will use this applet to log it into the system as a repair job. They will also be able to use the applet to manage the job e.g. allocate a person to carry out the repair and enter costs.
    You must not use a tool such as JBuilder to generate Java code. If you use code from elsewhere e.g. a text book, you must highlight the code and state the reference clearly and include a photocopy of the relevant pages from the text book or other source.
    You should hard-code some initial data into your applet. You should not store any data in a file or database.
    Level of functionality you should attempt to implement:
    Level 1 � Your applet should:
    a.     As a minimum, your program should store (in memory) at least 10 repair jobs. For each repair job, you need to store:
    �     The name and phone number of the customer bringing the PC in for repair;
    �     A brief textual description of the problem;
    �     Whether the PC is under warranty or not.
    b.     Your program must allocate and display a unique number for the job once it is accepted.
    c.     The user must be able to view the details of jobs. They should be able to select either:
    �     All the jobs in the system; or
    �     Jobs being carried out under warranty.
    Level 2 � Your applet must meet the requirements for level 1. In addition it should:
    a.     You should carry out appropriate validation checks on input data e.g. the phone number contains all digits.
    b.     System should cope with an unlimited number of jobs.
    c.     The user should be able to select a job and then allocate a repairer to that job.
    d.     The user should be able to display a list of jobs for each repairer.
    Level 3 - Your applet must meet the requirements for level 1 and 2. In addition it should allow the user to:
    a.     Select a job and input the cost of repair for:
    �     the number of hours labour;
    �     parts.
    b.     Select a job and present the user with a cost for the labour (hard code an hourly labour cost) and parts, plus a total for that job. For jobs under warranty the total will be zero, however the cost of labour and parts will be shown.
    c.     Be able to inform the business of the total expected income from the all the jobs in the system that are not under warranty.
    Level 4 � Your applet must meet the requirements for level 1 to 3. In addition:
    a.     The user should be able to enter a job priority which can be identified as high, medium or low.
    b.     Each repairer should be able to view a list of their jobs in order of priority.

    Done, what next ?
    Noah

  • I am using the mac QQ and when I login it said login timeout.

    I am using the mac QQ and when I login it said login timeout.

    If you are missing using google maps - try the Nokia map app called "here"

  • My LR 4 suddenly no longer recognized my memory cards. I am using the same cards and cameras but consisitently get the error message:"files not imported because the files could not be read. they are jpg and nef files...I am stuck without my workhorse! Any

    My LR 4 suddenly no longer recognized my memory cards. I am using the same cards and cameras but consisitently get the error message:"files not imported because the files could not be read. they are jpg and nef files...I am stuck without my workhorse! Any advice is helpful. This has never happened in 6 years

    answered in your other thread LR 4 suddenly no longer recognizes files.

  • I am using the MODBUS library and can't receive data, however I can send it just fine?

    Hi,
    I am using the Modbus Library to communicate with a VFD to control a fan. I am using the master write and read vi. I can write data to the VFD and get the fan to do what I want. The VFD is supposed to send a confirmation packet after I tell it to do something and I can also read its registers. When I debug the VI it shows the problem is the buffer always reads zero and the VI timesout. If I watch the lights of the USB to RS 485 adapter I am using to interface with the VFD, I see that the RX light flashs right after I send a message. So I should have something in the buffer. Does anyone have any suggestions?
    Aaron
    Solved!
    Go to Solution.

    Ok, heres what happened for anyone who has this problem. In the MB Serial Receive.vi The Bytes at Port property node was reading 0 even though there was something in the buffer. The program execution was then stuck in a loop till it timed out and never went on to read anything from the serial port buffer. I didn't spend too much time wondering why that VI didn't work and created my own. With an appropriate delay after writing to the serial port,  I used the same Bytes at Port property node and was able to get the right number of bytes to then feed the read VISA vi the number of bytes to read. I got the right response message and everything seemed good. But of course NOT! I then experimented with writing different speeds to the VFD to get the fan to run at different speeds. I found a small range of speeds where I would get no response from the VFD, either by it functioning or sending me a response packet. After quite some time, I found there is an error in the LRC-8 code in the MODBUS NI library. It does not mandate the LRC be a two character value. So if your LRC turns out to be a single character value such as F (which should be 0F)  you get an incomplete MODBUS message. This was easily fixed in the LRC8 vi by telling the 'number to hexidecimal string' vi to produce an output with a minimum width of two. Then everything worked great. Moral of the story is the MODBUS library is clunky.

  • I am updating iphoto 9.1 to 9.3 and every time when I clicked for update aps store asked to open it in the account where you purchased. I am using the same account and its available in the purchased item of this account. Can someone resolve this problem.

    I am updating iphoto 9.1 to 9.3 and every time when I clicked for update aps store asked to open it in the account where you purchased. I am using the same account and its available in the purchased item of this account. But in my purchased item library it indicates that you update iPhoto. I am not sure which account the aps store asking. Can someone resolve this problem.

    Contact App Store support. They're the folks who can help with Account issues.
    Regards
    TD

  • I had to take my hp back to factory setting and reinstall itunes, when I tried to use Itunes match it said i had to Deauthorize all my computers. I am using the same computer and desperately need access to my music.

    I had to take my hp back to factory setting and reinstall itunes, when I tried to use Itunes match it said i had to Deauthorize all my computers. I am using the same computer and desperately need access to my music.

    When you reset to factory settings, the computer is de-authorised.
    In iTunes menu Store > View Account > sign in > App Store > Deauthorise All.
    Once done, authorise this computer iTunes.
    Note: you can only do that once a year.

  • Hi. I am using the iPhone 4S and when I'm searching for places using Google it does not automatically detect my location. How do I change this?  FYI...under settings i

    Hi. I am using the iPhone 4S and when I'm searching for places using Google it does not automatically detect my location. How do I change this?  FYI...under settings i

    If you are missing using google maps - try the Nokia map app called "here"

  • Hi. I am using the iPhone 4S and when I'm searching for places using Google it does not automatically detect my location. How do I change this? FYI...under settings i have it set at "Use new precise locations from my device."

    Hi. I am using the iPhone 4S and when I'm searching for places using Google it does not automatically detect my location. How do I change this? FYI...under settings i have it set at "Use new precise locations from my device."

    If you are missing using google maps - try the Nokia map app called "here"

  • I recently bought a new macbook pro and set it up using the migration assistant and my mac mini.  I can't get the text message forwarding feature to work with both computers.

    I recently bought a new macbook pro and set it up using the migration assistant from my mac mini.  I can't get the text message forwarding feature to work with both computers.  It keeps saying that I only have 2 devices setup, my iPad and my macbook pro.  When I mess with the setting on my mac mini, it goes from saying that that is one of the devices to my macbook pro being the 2nd device.  I think that something happened as a result of my using the migration assistant and now it thinks that my macbook pro and my mac mini are one and the same computer.  Any ideas?

    Thanks, Sig.
    The old computer is a 2.6 Ghz Intel Core 2 Duo
    The new one is a 2.3 GHz intel core i7
    In going over this, thanks to "tallking it out" with you, I did discover the Text Edit problem.  Because I've still been unable to get the new computer text size (fonts or whatever) to match the old computer, I did not notice that the curser is now different--the line midway down the curser has to be placed on the line I am working upon, otherwise the edits go elsewhere on the page.  Now, with a bit of difficulty, I am able to get Text Edit to work correctly.
    If you have any ideas as to why my menu bar and Text Edit type are still so slow, I'd love to have them. 
    (I went through the process you suggested earlier, re my Trackpad preferences, and found no improvement.)

  • PS CS5 Extended on Windows -  When trying to use the clone stamp and/or healing brush as soon as I move the cursor over the image I get an exact copy of the existing layer that moves around the window with the movement of the clone stamp/healing brush.  W

    PS CS5 Extended on Windows
    When trying to use the clone stamp and/or healing brush as soon as I move the cursor from the toolbar over to the image I get an exact copy of the existing layer that moves around the window with the movement of the clone stamp/healing brush.  This just started tonight.  What's causing this weird behaviour?

    What are the settings in Window > Clone Source?

  • How to set up two POP e-mail accounts using the same POP and SMTP servers

    I have an e-mail address based on a domain I purchased which is based on my company name. Now retired, I have purchased a new domain with a simpler, personalised name. My original e-mail account uses the incoming (POP3) and outgoing (SMTP) mail servers operated by my ISP; mail.btinternet.com.
    I have set up a new account on my PC in Microsoft Outlook, and have successfully sent and received emails using the new e-mail address taken from my new domain name.
    I have now tried to mirror this on my iPhone, but every time I enter all the relevant data for the new e-mail address, user name, password, mail servers etc., and then press 'save', I get a pop-up which says: "xxxx" is Already Added  This POP account has already been added to your iPhone. ("xxxx" is the name given to my original e-mail account).  Nowhere have I input "xxxx" in the course of setting up the new account.
    I need both accounts operational during an extended switch-over period as I alert everyone to the e-mail change over. Can anyone suggest a solution to this problem?

    What targeting the Mail.app preference file, do the following:
    Quit the Mail.app first and using the Finder, go to Home > Library > Mail. Copy the Mail folder and place the copy on the Desktop for backup purposes.
    Using the Finder, go to Home > Library > Preferences > com.apple.mail.plist. Move the com.apple.mail.plist file to the Desktop.
    Note: Moving the com.apple.mail.plist file out of the Preferences folder will require re-entering all email account information when re-launching Mail.
    The only exception to this is if you have a .Mac account which will be recreated automatically and/or if you created an email account as part of the computer setup assistant when first turning on the computer when new.
    Launch Mail and decline any prompt to import mailboxes. After re-entering all email account information, the Mail.app should rediscover the existing account named folders and mailbox files at Home > Library > Mail.
    After confirming all mailboxes were successfully rediscovered, you can delete the copy of the Mail folder and old com.apple.mail.plist file from the Desktop.
    Test if this resolves the problem.

  • How to get the job logs from sm35 by using the queue id and session name?

    hi all,
    can any one please let me know how to read the job log from sm35 by using the session name and queue id. i have the job name and job count but is it possible to download the job log by using the queue id and session name.
    FYI..
    i want to read this job log and i want to send it to an email id.
    -> i am using the job_open and submitting the zreport via job name and job count and then i am using the function module  job_close.
    but this is not working in my scenario i have the queue id and session name by using this two i want to get the job log is there any function module available or code please provide me some inputs.
    thanks in advance,
    koushik

    Hi Bharath,
    If you want to download it to the local file then you can follow the instructions in the below link.
    How to download Batch Input Session Log?
    Regards,
    Sachin

  • HELP! My old mac was requested to upgrade Firefox to 14.0.1. After the sucessfully installation, I received a message saying my old Mac couldn't use the new Firefox and Safari crashes. I have NO browser now!!!

    My old mac was requested to upgrade Firefox to 14.0.1. After the sucessfully installation, I received a message saying my old Mac couldn't use the new Firefox and Safari crashes. I have NO browser now! Any help would be appreciated.

    Hmmm...  So you upgraded Firefox and now neither Firefox or Safari will work?  Very weird.  I have no idea what might have gone wrong.  That said, when things start acting wierd, I always try a bit of maintenance first.  About 95% of the time, I luck out and it works.
    I use the free program Onyx.  I run all the clean up routines.  Then I boot to the recovery partition (Lion) or the OS X Install Disc and repair permissions and verify/repair the hard disk.
    Hope this helps.

  • I have an iTunes account with a $25.00 credit but everytime I go to purchase a song, it goes to my credit card details. How do I use the iTunes credit and not the credit card?

    I have an iTunes account with a $25.00 credit but everytime I go to purchase a song, it goes to my credit card details. How do I use the iTunes credit and not the credit card?

    Just to confirm, you are logged into the iTunes Store using the account in which the balance exists, and the balance is showing at the top of the iTunes Store window? And you're not trying to purchase gifts for someone else?

Maybe you are looking for

  • FireFox 4 is slow for 64bit Windows 7

    Hello, Ive been using FF4 for over a month now with my old laptop using Windows Vista - 32 bit.. But my laptop recently crashed so I got a new one with Windows 7 - 64 bit. I installed firefox 4 and readded all my bookmarks manually because there was

  • Interview question for sql statement

    Hi Guys, In a interview i was asked the following question considering i m using database 9i Quote If a client is running a query and that client complains you that query is stuck and he is not sure if that query is slow or it is not running at all,

  • WARNING: JTS5020: Invalid log path when connecting to JTS

    Hi I am using JNDI to connect to JDBC resources defined in Sun's App Server from a standalone application. The application is not part of the J2EE container. I was able to sucessfully connect and execute SQL against the db passing VM params... my pro

  • I got the error "your work repository is not up to date"

    Hi guys, After a failed process of upgrade from 10g to 11g I got the error "your work repository is not up to date", this when I try to access to Designer Navegator. I attempt to access using the repositories cloned, and the original repositories I r

  • Mainstage 2 between keyboard and tone generator

    I'm having some problems trying to do the following: I have a keyboard (midi controller) and a tone generator. I want to create different controls that respond to the keyboard knobs and then send midi messages to the tone generator. This way I would