How to catch paste/copy events in JTextField?

Hi,
I am trying to get paste/copy events in a JTextField when user uses CTRL-V or CTRL-C to paste or copy texts. Here is what I do:
int keyCode = e.getKeyCode();
if (keyCode == KeyEvent.VK_V) {
    System.out.println ("CTRL-V pressed");
    String pastedText = getText();
    System.out.println ("pasted text is " + pastedText);
}but I cannot catch both events and pasted/copied texts.
Any suggestions?
regards,

Thanks,
The strange thing is, every time I use ctrl-v, ctrl-c, or ctrl-x to paste/copy/cut, there is always a special character (like a small square, or rectangle?) showing up at the end.
I have to use jdk1.4.1 since I am working on a old product. That does not happen in jdk1.5 environment.
I used getText() to get pasted text and then did a trim like this:
String pastedText = getText().trim();But it seems the length of a pasted text is still the same after trim.
How can I get rid of this unwanted special character?
Thanks,

Similar Messages

  • How to catch the mouse event from the JTable cell of  the DefaultCellEditor

    Hi, my problem is:
    I have a JTable with the cells of DefaultCellEditor(JComboBox) and added the mouse listener to JTable. I can catch the mouse event from any editor cell when this cell didn't be focused. However, when I click the editor to select one JComboBox element, all the mouse events were intercepted by the editor.
    So, how can I catch the mouse event in this case? In other word, even if I do the operation over the editor, I also need to catch the cursor position.
    Any idea will be highly appreciated!
    Thanks in advance!

    Hi, bbritta,
    Thanks very much for your help. Really, your code could run well, but my case is to catch the JComboBox event. So, when I change the JTextField as JComboBox, it still fail to catch the event. The following is my code. Could you give me any other suggestion?
    Also, any one has a good idea for my problem? I look forward to the right solution to this problem.
    Thanks.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test3
    extends JFrame {
    // JTextField jtf = new JTextField();
    Object[] as = {"aa","bb","cc","dd"};
    JComboBox box = new JComboBox(as);
    public Test3() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = getContentPane();
    String[] head = {
    "One", "Two", "Three"};
    String[][] data = {
    "R1-C1", "R1-C2", "R1-C3"}
    "R2-C1", "R2-C2", "R2-C3"}
    JTable jt = new JTable(data, head);
    box.addMouseListener(new MouseAdapter() {
    // jtf.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e)
    System.out.println("-------------------JComboBox mouseclick....");
    jt.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e)
    System.out.println("-------------------JTable mouseclick....");
    // jt.setDefaultEditor(Object.class, new DefaultCellEditor(jtf));
    jt.setDefaultEditor(Object.class, new DefaultCellEditor(box));
    content.add(new JScrollPane(jt), BorderLayout.CENTER);
    setSize(300, 300);
    public static void main(String[] args) {
    new Test3().setVisible(true);
    }

  • How to catch the ApplicationStart event??

    how to catch the application start event??
    i want to do some actions (Java code) that will be run once when the application started
    this like ApplicationStart event in ASP.NET
    how ???

    Google for javax.servlet.ServletContextListener. You need to write a class that implements this interface and register it in web.xml.
    Please ask questions like this in the JDeveloper or OC4J forum since they are not related to JHeadstart.
    Steven Davelaar,
    JHeadstart Team.

  • How to catch browser close event excluding navigation events

    Hi,
    I tried using onBeforeUnload event and onUnload events.. but they are catching navigation events within the same site. Could you please let me know how I can catch browser close events without catching Navigation events?
    Thanks.

    Just set them to null when navigation takes place.
    Said that, you should be asking Javascript/DHTML related questions in a forum devoted to Javascript/DHTML. There are ones at webdeveloper.com and dynamicdrive.com. This has nothing to do with Java.

  • How to catch menu click events from B1AddOn Wizard

    Dear Friends,
    I'm adding some custom menus to the SAP BO main menù using B1 Addon Wizard generated code, but then I don't know how to catch the events generated by the menus.
    Thank you for attention
    Massimo

    Thank you Eddy,
    I had a look at the help, but there it is not explainsed that events can be attached only to string menus!!
    It was attempting to do something wrong.
    A further question: is it possible to add new menus and related events to an existing project (I tried with new item and then B1 Addon Component, but it doesn't let me add new menus)?
    Thanks again
    Masimo

  • LV7: how to catch 'Value change' event for cursor position in XY graph?

    I try to catch an event when the cursor position of a graph's cursor
    changes. I created a reference for the cursor array and registered a dynamic
    event 'Value change' for it. The event does not fire when the cursor changes
    (either by dragging it with the mouse or by direct entry of a new value in
    the cursor's X or Y fields. In contrast, when I register e.g. the 'Mouse Up'
    event for the cursor array, the event IS detected.
    -Franz

    So this is the same behaviour as that of a regular control which also does
    not fire a 'Value changed' event when it gets updated by e.g. writing to a
    local.
    At least the cursor's behavior is consistent then...
    But unfortunately also the direct user interaction with the cursor's numeric
    field does not fire the event, which is NOT consistent.
    I was trying to catch cursor changes in my event loop and had used a 'Mouse
    Up' event of the graph indicator to look for cursor changes (whose last
    position I had kept in a local or shift reg). In order not to miss a direct
    user interaction in the numeric field I added the dynamic event 'Value
    change' to the same event case, but with no success, it missed the direct
    entry ...
    according to what you say this seems to b
    e a bug then...
    -Franz
    "Greg McKaskle" schrieb im Newsbeitrag
    news:[email protected]..
    > > I try to catch an event when the cursor position of a graph's cursor
    > > changes. I created a reference for the cursor array and registered a
    dynamic
    > > event 'Value change' for it. The event does not fire when the cursor
    changes
    > > (either by dragging it with the mouse or by direct entry of a new value
    in
    > > the cursor's X or Y fields. In contrast, when I register e.g. the 'Mouse
    Up'
    > > event for the cursor array, the event IS detected.
    > >
    >
    > The reason is that value change events fire when user action directly on
    > the control changes its value. They do not fire when other programmatic
    > value changes occur. If you are looking at a value change on the cursor
    > palette, user interaction with the numeric should fire it, but updates
    > due to cursor movement are more like programmatic updates.
    >
    > Additional events will likely be added in future
    releases, and these may
    > make it easier to catch cursor movement events on a graph.
    >
    > Greg McKaskle
    >

  • Cannot paste copied events

    Hi,
    My boss asked me to help him bring over a bunch of events from a google calendar to a local calendar. First of all, it appears in iCal 3, there's no way to select all events like you could do with the search results pane in iCal 2. I discovered that if you type doublequote-spcae in the search field, you can do it, but that's extremely unintuitive. Anyway, I was able to select all the events and copy them, but when I clicked on the calendar I wanted to paste them to, 'paste' was greyed out. What the heck? I do this all the time in iCal 2. Why can't I do it in iCal 3? Is it because the calendar was created by google calendar? I couldn't even find a single .ics file in ~/Library/Calendars which had all the events from one calendar. I figured out I could export the calendar from google and then import, but what if I don't want the whole calendar? Come on!

    Fair enough.
    I did specify what I tested it with.
    Since the OP implied that it worked before an update to the Firefox browser, but not after that is why I suggested testing with other browsers including the one that I used successfully.
    However remote the possibility, there was the thought that the update could somehow have damaged some system file or other shared file.
    Regardless, a suggestion has been made for a workaround. That method can also be used to generate images for linking via the Place command.
    -mt

  • Personas 2.0: How to catch the selection event of a dropdown list?

    Hi Personas 2.0 experts,
    The use case:
    I want to use a text field to show the "key" of an item that can be selected in a dropdown list.
    The issue:
    After clicking the list and selecting an item, the text field is not automatically updated with the newly selected item content.
    Anyone has an idea to how make such an auto update (pls note I don't want to use an extra button to do the update, just by clicking the list only)?
    Thx.
    Dong

    To display the key (the actual value) that's selected in a dropdown, there is a property called ShowKeys which you could set.
    However if you'd want to show the selected value in another field upon picking an option, this would require an event associated in Personas 2.0 with the selection of a dropdown value. This is currently not available so I'm afraid what you are looking for is not possible.
    Edit: It turns out I was wrong... there is an option (at least it's there in SP3) which allows linking a script button to the dropdown property OnValueChanged, so you can use this to do any script action you need when the user selects a value.
    (thanks, Sushant )
    Message was edited by: Tamas Hoznek

  • How to catch window maximised event ?

    I know I need to creat class that will implement WindowListener. But what even should I catch ?? And also... I need to restrict this function... so my window can't be maximised... how do i do this ? Any hints ??? Please help.

    For the first problem you should use the componentResized() method of the ComponentListener interface: in this method, just call yourFrame.getExtendedState() and compare it with JFrame.MAXIMIZED_BOTH... that will tell you if the frame has been maximized.
    For the second point, use the same principle: after the above test, if the frame is maximized you can resize it to whatever dimension you like.
    The code would be:
          yourFrame.addComponentListener(new ComponentAdapter() {
             public void componentResized(ComponentEvent e) {
                if (yourFrame.getExtendedState == JFrame.MAXIMIZED_BOTH) {
                   yourFrame.setSize(300,300);
          });Of course, the given size is for example.
    Hope this helped,
    Regards.

  • How to catch ALL call events with JTAPI

    Hi,
    I have my JTAPI application witch is listening for ALL calls that are placed on CUCM system. Based on this information this software is making some routing decisions. At present getting the information about all calls is very inconvenient - I have to track all events from all phones, so my CTI user has to have ALL phones on its Controlled Devices List.
    Is there more intelligent way of getting all call events without controlling every single device? I am interested in any version of CM or CUCM.
    Regards,
    Andrius Kislas
    CCIE #18338 Voice

    According to the documentation, lineMonitorTones should be available (though that's the 7.0 documentation I'm looking at) - going through a wrapper always add another place where things can go wrong. E.g. we're supposed to get device state events with the latest version but when I tried I still got nothing. If you can handle tapi browser you might want to try it and see if it works, and if so, get in touch with the developer of the lib (I did once... really nice and helpful guy).
    Alternatively, there's no need to catch digits.. you may not even be able to terminate the call in the status you're looking at so you could just listen to call events and get the first one where the call actually starts (as in "all digits dialed") and terminate it then.. it probably won't make much of a difference either unless you want to prevent people from making certain calls and cut them off after a few digits.. but that is better done using partitions and css.. they are meant to prevent people from calling certain numbers and it would be ill advised to duplicate this functionality in your own software (which after all could fail every now and then.. or the app could lose the connection to the server, etc.)

  • JavaScript in PDF: catch copy event

    Hello everyone!
    I hope this is a right place to ask my question.
    I have two questions about PDF documents.
    First. Can I make Acrobat Pro/Reader copy text with leading spaces? I mean to say if there is some text row and at the beginning of it there are some spaces, than when I'm trying to copy that line - I'll get only text and not leading spaces.
    For example I have a line:
                                                 Some text here
    and after I'll copy it from PDF and paste it in notepad I'll get next row:
    Some text here
    Can I change this behavior somehow?
    Second. I want to place a page number in buffer when copying. So, if on page number 5 there is a line I'm going to copy, after paste I want to get something like that:
    Page 5
    Coppied line
    I was trying to use JavaScript for this, but I did not found any way to solve my problem. Is it possible at all? And if possible, in what dirrection I should take a look?
    With regards
    Viktor

    It's actually not the right place for this question. It belongs in the Acrobat Scripting forum...
    But anyway, the asnwer to both questions is no.
    The position of text in a PDF is not created by adding spaces or tabs before it, so you can't copy them when you copy the the text.
    The same goes for JavaScript, which can only get single words out of the text.
    JavaScript also can't "catch" the copy event. The closest you can get is to execute the Edit:Copy menu item through JavaScript's execMenuItem(), but you can't influence the text that is being copied, so you can't add the page number before it.

  • How to catch call events?

    Hi, I'm trying to develop a java application for mobile devices (mobile phones) that should automatically Reject when somebody calls (based on some rules).
    I don't know how to catch the "+call event+".
    Can anyone help me ?

    Hi,
    This is not possible using core Java ME (CLDC + MIDP). You can initiate a call in MIDP 2.0 by using platformRequest.
    The optional JSR 253 makes it possible to do what you want do do, but I haven't seen any devices with this JSR implemented.
    http://jcp.org/en/jsr/detail?id=253
    -henrik

  • How to catch window event on jApplet

    Could you please let me know, How to catch �activate window� event on Japplet page. I am using the following class.
    public class CtApplet
          extends JApplet
          implements Runnable, ErrorHandlerI could implement the same on Jframe by using the following Api�s. I assume they don�t exist on Japplet.
    this.addWindowListener (��.);
    class ��
          extends java.awt.event.WindowAdapter
        public void windowActivated (WindowEvent e)
            ��..
    }Edited by: samtek on Oct 30, 2007 7:59 PM
    I extened my japplet class from WindowListener, and added function, windowActivated(), But not able to catch the event.

    Hi,
    I would try AWTEventListener; it should work with a JFrame.
    Now I probably could have done this better but I made 2 classes for this.
    HyperFrame to run the applet as an Application and have the Frame handle
    the AWT events, and AWTEventManager to process the Events when running as an Applet. In the future I will probably merge into 1 AWTEventManager.
    https://hyperview.dev.java.net/source/browse/hyperview/www/HyperView299/AWTEventManager.java?rev=1.3&view=markup
    https://hyperview.dev.java.net/source/browse/hyperview/www/HyperView299/HyperFrame.java?rev=1.11&view=markup
    Anyway, omit the View/List specific code and look at the setup; it should work for you. BTW Not ATM multi instance friendly but on my todo list several hundred down.
    You will need to tweak the Thread control as well; probably AWTEventManager is the class to study as it really shows all you need to implement an AWTEventListener
    Good Luck!
    (T)

  • How to handle tab change event in UI shell main area

    Hi,
    I have two tabs(two taskflows) in UI shell main area. one is department tab and another is employee tab. My department tab shows employees department wise. On employee tab I have emplyee table which shows employees jobwise. This employee table has the functionality of adding new record to employee vo as well.
    Now i follow these steps.
    1. by defualt department tab is open.
    2. by clickinng on Tasks menu link i open Employee tab in to main area. Now i have both tabs in main area.
    3. at Employee tab I search all employees job = accountant. It shows the search result well.
    4. Now i add a new record to it and without saving/deleting this record i move to department tab.
    5. at Department tab i search employees where department =20, here no relation b/w job and department.
    6. Now i return to employee tab. my newly added record got disappeared. It is there but does not show in table.
    How to resolve it??
    I have one solution in my mind while changing the tab i can prompt to user "you can not leave the newly added record..either save it or delete it". But how to catch tab change event here? where i can write code to prompt msg to user?
    Pls help.
    Edited by: 900997 on May 6, 2012 4:10 AM

    With apologies for the slow reply, I'm currently travelling.
    Two things to note:
    1) The af:document uncommittedDataWarning flag was designed to stop users navigating away from half entered records. More about this flag can be found here:
    http://docs.oracle.com/cd/E23943_01/web.1111/b31973/af_orgpage.htm#CACDDDFH (see point 4)
    http://www.oracle.com/technetwork/developer-tools/adf/unsaveddatawarning-096556.html
    ....please note our documentation from time to time spells this flag wrong with only one "t" in the word committed, so if you're attempting a bulk search check for this (and I'll raise document bugs to get this fixed in the future).
    2) On addressing the ADF UI Shell, if you're switching between "pages" in the UI Shell, as separate to switching between dynamic tabs within a single page using the UI Shell, the UI Shell will actually restart the currently running task flow in the page you're returning too. You can verify this by implementing an initializer on your task flow with a log message, and watching when the initializer is called.
    In addressing your last question, at this stage I think you need to assess my first answer then come back if you think you sill need to execute the code on the tab click. I also need to know are you talking about the primary level of tabs that represent each page in the UI Shell, or are you referring to the dynamic tabs within a single UI Shell page that hold your task flows?
    CM.

  • How can I copy and paste an event in calendar?

    In the ios5 version of calendar you can cut and paste an event by simply dragging it from one day to another in month view. However I can see no way of copy and pasting a recurring (but irregular) event. As someone who works irregular shifts I would love to be able to do this to build a calendar of my working month.

    Open one document in Pages v5.5.3, Open a second document in Pages v5.5.3. Select, copy, and paste one page between source and destination documents. Document objects such as Text boxes, shapes, images, tables, etc must be individually selected, copied, and pasted.

Maybe you are looking for