Cut and Paste - Data Validation - JEditorPane

I have an editor in development that uses JEditorPane which is supposed to accept only certain characters as its input.
Now if I use keystroke I am able to handle the input data entered using keyboard and it seems this is not a good idea :(.
But, for cut and paste this method does not work. So my questions are,
1) What is a good way to do data validation for Paste operations
2) I know that I might need to have a custom document but where do I do the validation in the custom document. I have checked using print statements and for my paste operation, it seems that the insert method in document does not get called.
3) Is using system clipboard and checking the text before insertion a better option.
4)What exactly happens when paste ie control C is pressed or paste from menu is clicked. I mean sequence of method calls.
I know I have asked many questions but answers to any of them will be highly appreciated !!
Thanks a lot for your help in advance :)

In my application, I subclass JTextField but you should be able to change it to JEditorPane. Here is a snippet of code that you need:
public class myTextField extends JTextField implements ClipboardOwner {
   public boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
      if (ks==KeyStroke.getKeyStroke(KeyEvent.VK_V,2)) {     // CTRL-V (paste text from clipboard)
         pasteText();
         return true;
      }   // there is more to my code but this will do
      return super.processKeyBinding(ks,e,condition,pressed);
   private void pasteText() {
      try {
         Transferable contents=clipboard.getContents(this);
         if (contents==null) return;
         int i=getCaretPosition();
         String line=(String)contents.getTransferData(DataFlavor.stringFlavor);
         String tmp=getText();
         int sStart=getSelectionStart();
         int sEnd=getSelectionEnd();
         if (sStart>=0) {
            setText(tmp.substring(0,sStart)+line+tmp.substring(sEnd));
            i=sStart;
         } else {
            if (i<tmp.length()) line+=tmp.substring(i);
            setText(tmp.substring(0,i)+line);
         sEnd=Math.min(i+line.length(),getText().length());
         setCaretPosition(sEnd);
         select(i,sEnd);
      } catch (Throwable t) {
         if (ExtDB!=null) ExtDB.setError("",t);
   public void lostOwnership(Clipboard cb, Transferable transferable) {
}The above has been formatted to look pretty, the following is more suitable for cut-n-paste:
public class myTextField extends JTextField implements ClipboardOwner {
   public boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
      if (ks==KeyStroke.getKeyStroke(KeyEvent.VK_V,2)) {     // CTRL-V (paste text from clipboard)
         pasteText();
         return true;
      }   // there is more to my code but this will do
      return super.processKeyBinding(ks,e,condition,pressed);
   private void pasteText() {
      try {
         Transferable contents=clipboard.getContents(this);
         if (contents==null) return;
         int i=getCaretPosition();
         String line=(String)contents.getTransferData(DataFlavor.stringFlavor);
         String tmp=getText();
         int sStart=getSelectionStart();
         int sEnd=getSelectionEnd();
         if (sStart>=0) {
            setText(tmp.substring(0,sStart)+line+tmp.substring(sEnd));
            i=sStart;
         } else {
            if (i<tmp.length()) line+=tmp.substring(i);
            setText(tmp.substring(0,i)+line);
         sEnd=Math.min(i+line.length(),getText().length());
         setCaretPosition(sEnd);
         select(i,sEnd);
      } catch (Throwable t) {
         if (ExtDB!=null) ExtDB.setError("",t);
   public void lostOwnership(Clipboard cb, Transferable transferable) {
}This will force the paste action to trigger a call to insertString.
;o)
V.V.
PS: my preference for the use of processKeyBinding has been labled inappropriate, the proper method according to the experts in this forum is to use a combination of InputMap/ActionMap.... so, you decide what you want to do.

Similar Messages

  • Having a problem with dates when I send my numbers doc to excel. dates are all out and that they have to cut and paste individual entries onto their spreadsheet. Any idea how I can prevent this

    having a problem with dates when I send my numbers doc to excel. dates are all out and that they have to cut and paste individual entries onto their spreadsheet. Any idea how I can prevent this.
    I'm using Lion on an MBP and Numbers is the latest version

    May you give more details about what is wrong with your dates ?
    M…oSoft products aren't allowed on my machines but I use LibreOffice which is a clone of Office.
    When I export from Numbers to Excel and open the result with LibreOffice, the dates are correctly treated.
    To be precise, dates after 01/01/1904 are correctly treated. dates before 01/01/1904 are exported as strings but, as it's flagged during the export process, it's not surprising.
    Yvan KOENIG (VALLAURIS, France) mardi 3 janvier 2012
    iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2
    My iDisk is : http://public.me.com/koenigyvan
    Please : Search for questions similar to your own before submitting them to the community
    For iWork's applications dedicated to iOS, go to :
    https://discussions.apple.com/community/app_store/iwork_for_ios

  • How do I cut and paste an appointment and change the appointment date?

    I have just moved to the Iphone 3GS after many years on Windows Mobiles so it's all new to me, but how do I cut and paste appointment information?
    I also need to be able to change the date of an appointment, but could not figure out how.
    Thx
    Bryce

    That's fine for changing an appointment date, but is there a way to "copy" an appointment and paste it into a new date so that the date of the original appointment isn't lost?
    For example, I have an appointment that occurs every 4-5 weeks, and we set the future date at our meetings, but I need to be able to go back and review earlier when earlier meeting dates took place to be able to track milestones. If I simply change the current appointment date I'll lose that history.
    In Outlook I can simply copy and paste an appointment into a new date, but I'd like to be able to do so from my phone for when I'm not in my office. How can I do this?

  • Cut and paste operation in Hyperion Planning is slower than normal web page

    We understand the web form under Hyperion Planning has many useful functions built-in but we also encountered some user complains that the operation inside the web form is relatively slower than normal web page. When user cut and paste 20 to 50 cells content, they need to wait 1 to 5 seconds on the "copy" function.
    Any workaround can be implemented to improved the user experience? We have asked Oracle whether we can disable the SQL statement behind but no firm reply yet.
    Thanks a lot for your help!

    JohnGoodwin wrote:
    Hi,
    It has always been a bit of an issue, they supposely resolved in it earlier releases though I am not sure how much there really did resolve it.
    It is down to the amount of Javascript that is used in the web forms and how much rendering and validation it has to go through.
    The spec of client machines sometimes can have performance impact.
    One route is to use smart view to enter data into forms, as it is excel based it should be much quicker to cut/copy and paste.
    Cheers
    John
    http://john-goodwin.blogspot.com/
    John, thanks for your advice.
    Yes SmartView should improve the operational speed. However as not all of our users are using SmartView we are looking for some ways to improve the web form speed.

  • Won't cut and paste anymore

    Eversince the Mavericks upgrade, I can't cut and paste in the calandar app anymore. Let me try to explain:
    Every month, I get a new schedule for work, and I have to manually enter it in to my calander app. It then sinks to my phone, ipad and work macbood air. I only have 2 or 3 different catagories that I use for any given day, and I used to just copy one catagory from, say November 14th, and then click on November 29 and paste the same catagory and time. Now it will only paste on the date that I copied from (ie it'll just put another copy of the same job & time on the same day). 
    Is this happening to anyone else, or just me?

    Hi,
    It works as expected for me here on OSX 10.9.
    Best wishes
    John M

  • I can't be the only person who has this problem - when a month ends on a Saturday I can't drag events into the next month and instead have to cut and paste - a real pain in the butt. I thought there was something called "scroll" but I can't find that

    I can't be the only person who has this problem with iCal- when a month ends on a Saturday I can't drag events into the next month and instead have to cut and paste - a real pain in the butt. I thought there was something called "scroll" but I can't find that.

    Yeah that works, but, it involves a click on the event, a click on edit, a click on the date, keystrokes, plus, since you can't see the next month you have to have a calendar in front of you so as to put it to the right date. It's easier just to cut it and advance the month and paste it, once you are in the right month you can move it around helter skelter willy nilly no problems. Although now that you mention it I will try it, maybe it is easier than cut and paste as I don't really care about the date, as long as it gets moved into the right month I can drag it around all I want.

  • I can't seem to cut and paste text into the community message form?

    It seems I can't paste text data into this field.  Can you help?

    Win 7, explorer.  Cut and paste from any text source (Word, Notepad, Explorer) has the same result.  As an example, In this form window I cannot paste.  But, If I open a new discussion, toggle the HTML button, I can paste.  .  For some reason the reply form does not have the HTML button.  So, it might be a Java/browser thing - something is disabled.....
    I'll try Chrome and see if the same thing happens.
    I can cobble around it, but I've never seen this in any other HTML form before...

  • I can't cut and paste and the mac doesn't see me as the admin

    Okay so here are my current frustrations and issues:
    1. I can't cut and paste anything! Not from emails, not in documents, nothing.
    2. I went to make changes in the utilities and when I started, under my name, it said admin and now it says standard and the computer won't allow me to make changes. I try to enter my name and password and the computer says I am not the admin.
    3. I can't delete the "test" user and "guest" user because apparantly there is no admin.
    I have rebooted using the install disk and I was able to change the passwords but I still can't get in as the admin.
    Is there a way to override this before I a) pull out all of my hair, my husbands hair and the hair belonging to my cat and/or b) before I throw the machine out the window and then have another frustration that the unit is not working?! 

    First back up all your data, if you haven't done so already.
    Boot in safe mode (shift key down at startup) and check to see whether the clipboard now works. If it does, reboot as usual (not in safe mode) and try again.
    Next, boot in single-user mode by restarting the computer and holding down the Command and S keys at the chime, until you see white text on a black background. Wait for the text to stop scrolling, then follow the instructions on the screen, which will tell you run the fsck and mount commands. Be very, very careful to type the commands correctly. After you enter the mount command, please enter this:
    rm /var/db/.AppleSetupDone
    Then this:
    exit
    The Mac will now boot up as if for the first time. Go through the setup procedure to create a new admin account with the same name and password as the old one.

  • Can no longer drag or cut and paste links or words from one place to another with new Firefox update

    After updating Firefox 19.0.2 to my iMac Desktop 10.8.2, Lion, I can no longer drag or cut and paste anything to anywhere, anymore. Please help. Thanks!

    Does this also happen if you try to copy/cut and paste text in a text area like "Post a Reply" on this forum?
    Try to reinstall Firefox.<br />
    Download a new copy of the Firefox program and save the disk image (dmg) file to the desktop
    *Firefox 19.0.2: http://www.mozilla.org/en-US/firefox/all.html
    *Trash the current Firefox application (e.g. open the Applications folder in the Finder and drag the Firefox application to the Trash) to do a clean (re-)install
    *Install the new version that you have downloaded
    *https://support.mozilla.org/kb/Installing+Firefox+on+Mac
    Your profile data is stored elsewhere in the Firefox Profile Folder, so you won't lose your bookmarks and other personal data if you uninstall and (re)install Firefox.
    *http://kb.mozillazine.org/Profile_folder_-_Firefox

  • Can you cut and paste multiple lines of text in adobe forms?

    Hi -
    I am working on cutting and pasting large amounts of information into adobe forms. When I presently cut and paste from Excel, it puts all of the data in one line rather than in separate choices in a multiple choice selection.
    Is there a way to separate out this data so that from the excel sheet, each piece of data is separated into a different possible selection?
    Thanks,
    Laura M

    That's not the way of transferring data from Excel to a PDF form. You should format the data in two rows, the first being the field names and the second being their values, and then import it via Tools - Forms - More Form Options - Import Data...

  • Cut and paste from Word into Mail

    I have an earlier post where I thought I had solved this problem, but now it's back with a twist:
    I can cut and paste from Word, but after a few cut and pastes, it seems as if I can only paste the last successful section of text: copying new text from word seems to work, but when pasting into Mail, only the previous section of cut and pasted text appears.
    I have checked the preferences within Mail, and they are set for plain text... so there should be no problem, yes?
    I also tried quitting and then restarting Mail, but had the same problem...
    Any advice?

    Thanks, aqua*star -
    I just checked the "archiving" and "back-up" suggestions in the Mail "Help" window and got the following info:
    Mail preferences and messages
    Your Mail accounts, rules, signatures, and Smart Mailboxes preference settings can easily be backed up. Tip: All Mail-related preference files should be backed up or restored as a group.
    To back up:
    Note: These steps back up Mail preferences, but do not back up Mail messages (emails), although you can do that with the .Mac Backup utility. See below if you want to manually back up Mail messages (mailboxes).
    Create a uniquely-named folder on your desktop (or other favorite location). For example, you might call it "Mail Prefs Backups May152005" (adding a date is a good idea).
    Quit Mail if it's running.
    In the Finder choose Home from the Go menu.
    Open the Library folder.
    Open the Preferences folder.
    Copy the "com.apple.mail.plist" file to the folder you made in step 1 by Option-dragging the file. Don't remove the original file from its current location (this file contains your Mail accounts information).
    Close the Preferences folder.
    Open the Mail folder.
    Copy the "MessageRules.plist" file to the folder you made in step 1 by Option-dragging the file (this file contains your Mail rules).
    Copy the "SmartMailboxes.plist" file to the folder you made in step 1 by Option-dragging the file (you guessed it, this file contains Smart Mailboxes information).
    Finally, copy the Signatures folder to the folder you made in step 1 by Option-dragging the folder. (Your custom signatures, if you use them, are stored here.)
    To restore: Just move all of the copies of the files and folders from your uniquely-named folder to the original locations from which they came, as listed above.
    It looks like I can save and restore the Mail rules separately from the plist...

  • Cut and Paste function in Release 620

    Hi Experts - I was wondering if someone out there can help me. My question is how would I copy a column of data from an ALV grid and paste it into another area (variant). I can get it to select (highlight) the column but cannot get it to copy to clipboard for later pasting. If this is not working with this version, is there a way I can get the script to keypress the letter "C" so I can do a copy through right-clicking and bringing up context menu.
    Thanks
    Umur

    Hi umer ,
                I was reading and came acroos few good tricks in SAP.As if now I dont know, That you facing this cut paste for all application of SAP or is it only ALV.
    Anyways,
      I just wanted to tell you about quick cut and paste option which is available with SAP.
    On the standard tool bar we can opt for this option.
    CLick on customize local layout (Alt-F12) option in your local GUI setting and choose Quick cut and paste..
    This way you can copy cut paste just by highlighting the text desired for copying.And the place the cursor on the place where you want to paste and just click the right button of the mouse.It is really amazing and comfortable.Just try it out .Hope it works out for you.Remember we need to activate using above options.
    Hoping your query will be solved.
    Have a best day ahead.

  • RAR5.3 not able to cut and paste list of users to Multiple Selection screen

    CC V4.0 on ABAP system has a feature where you can cut and paste a list of many users from the clipboard to Single Values column in the Multiple Selection screen, so you can run SOD Analysis Report for all those users.  The Multiply Selection screen is a standard SAP supplied pop up screen.
    With RAR 5.3 the Multiply Selection screen design is different.  There is no longer feature to cut and paste from clipboard.  We have to input each user one at a time.  So if you have many users (20, 30, etc.) it is a time consuming task.  It is not acceptable to our business power users.
    We can import the list of users to a Custom User Group (in the Configuration Tab).  First of all, there is no mass delete on Custom User Group.  You have to delete each user one at a time which is time consuming.  The alternative is to create a new Custom User Group each time, then it becomes a maintenance nightmare.  Secondly, it is in the Configuration Tab which is only available to Administrators (fear of users changing configuation data), so the Administrator (or whomever has access to the Configuration Tab) has to maintain the Custom User Groups which is a lot of work for him or her or them.
    We talk to SAP every week.  But they are looking at this as a long time project.  Does any one of you (or your company) has the same requirements?  How do you get around it?  Did you setup some other procedures so users can cut and paste the users list and run the Risk Analysis report themselves?
    Thanks,
    John.

    This is probably a JVM issue. Are you using JInitiator or the IE native JVM?
    I suggest you turn on the JVM console, set the trace level to maximum, and then watch what happens when you attempt the copy.
    Also, check the key mapping (usually ctrl-k) that the forms applet is implementing. Perhaps ctrl-c means something else...

  • I synced with a new computer. Lost apps, reinstalled, had docu in an office2HD app when reinstalled, but will not cut and paste?

    I synced with a new computer, lost apps. Reinstalled and office2HD had all docs still in, but now I can not get the cut and paste feature to work? Also had problems with Gmail account and deleted and created new, so not sure I can download the app a 3rd time?

    Two ways.
    - You can sync with the new computer by following these instructions
    Sync Your iOS Device with a New Computer Without Losing Data - How-To Geek
    All the apps have to be in the iTunes library so the app data will have a place to go.
    - Or just restore from iCloud backup. That will also pull down the apps from iCloud. Your apps data will also be restored.

  • How to Cut and Paste a file on Mac

    Hey guys,
    Nice to meet you here. I am a new Mac Book Pro 13" Retina Display user with OS X Yosemite. I just switched to Mac from Windows last week.
    So far I have a great experience using Mac. However one thing is troubling me. How do I cut and paste a file? I've tried command+x and command+v but it doesnt work. I can copy and paste though by using command+c and command+v.
    Your help is greatly appreciated.
    Thanks,
    Arief

    nice pick...........
    I mean that i dont have to cut and paste just data in
    that files, but i have to cut and paste whole file
    from one location to other.
    Yup, if you need to do that physically you walk over to the filing cabinet, get the file out, cut it to pieces, take the pieces to the new location, glue them back together, and put the recreated file in the new filing cabinet.

Maybe you are looking for

  • How can I use an iTunes credit (from a gift  card which has been entered) for a book burchase?

    I have entered a $25 gift card and would like to use it for a book purchase. When I ordered a book it was charged to my credit card not the iTunes credit.

  • Upgrade and plug ins migration ? speed changes and transitions to motion 3

    I have the FCS2 upgrade on its way soon i hope.. will my natress plug ins and others migrate when i go from FCS1 to 2? I am mid project - have done all my captures but havent got into the nitty gritty of the edit yet - you reckon its a bit risky to u

  • Randomly quitting applications

    When I am using applications they randomly close out. The screen just goes to the desktop.

  • Settlement of PM Order

    Hi all, How can you determine that the costs in an order is fully settled? There is no automatic system status for it. When u do the settlement in K088 & set the status manually as 'business completion', it signifies full settlement. Is there any oth

  • Hard drive read/write problems

    I have three external hard drives connected to my iMac that are always on with the computer. Just recently, I started having trouble with permissions. Every day I have to go into disk utility and click "verify disk" to be able to write to the drive,