Need Cut/Copy/Paste Actions when Right click on JTextArea,JTextField

How to Implement Cut/Copy/Paste from Contextmenu in JTextFeilds and JTextAreas.
Thanks and Regards,
PavanKrs

Untested code, may take some massaging to work, but this is the gist of it:
JPopupMenu popup = new JPopupMenu();
JMenuItem item = new JMenuItem(new DefaultEditorKit.CutAction());
item.setText("Cut");
popup.add(item);
item = new JMenuItem(new DefaultEditorKit.CopyAction());
item.setText("Copy");
popup.add(item);
item = new JMenuItem(new DefaultEditorKit.PasteAction());
item.setText("Paste");
popup.add(item);
textField.setComponentPopupMenu(popup);

Similar Messages

  • Using Default Cut/Copy/Paste Actions

    After reading through the posts here, it seems that a lot of people use the method in the tutorial to implement cut/copy/paste in menus and toolbars.(http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html)
    I tried this, and it works, but the toolbar and menu entries are set to "cut-to-clipboard", etc. I have tried applying setName, but it doesn't seem to help. I want to be able to show just "Cut" with the appropriate icon.
    Anyone know what I'm missing?
    adam

    cutAction.putValue( Action.NAME, "Cut" );

  • JList & cut/copy/paste and focus

    I have a JFrame with a typical edit menu (cut/copy/paste) and also a JList. I have hooked up the menus such that cut copy paste 'do the right thing' in regards to the current selection of the JList. However, if the JList has focus and i keyboard ctrl-x for instance, it looks like the JList is grabbing and handling the cut, as opposed to my menu code. How do I get the JList to ignore the keyboard when it has focus, or do I install my handlers in the JList somehow?

    Thanks for the response. This area really smells to me. Which I infer means i don't really understand this area, otherwise it wouldn't be so wretched.
    For instance the default cut action on a JList, doesn't seem to do anything, while the copy works correctly.
    So why would you ever use the default actions? I guess i can install my menu actions in the JList, just seems badly designed... so am i wrong?
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class MyJListFrame extends JFrame
         public static void main(String[] args)
              MyJListFrame f = new MyJListFrame();
              f.setVisible(true);
         public MyJListFrame()
              Container cp = getContentPane();
              DefaultListModel dtm = new DefaultListModel()
              {{addElement("This");addElement("is");addElement("a");addElement("test");}};
              cp.add( new JList( dtm ));
              pack();
    }

  • The right mouse button on my 8740w has failed (clicks but no result, i.e Cut/Copy/Paste/Delete menu

    My right mouse button clicks but no result, i.e Cut/Copy/Paste/Delete menu does not appear.
    I think the hardware has failed.
    Note the mousepd is not the issue.  The right button is the problem
    Left button works fine

    Same deal with me except the right button has failed twice. You may find that if you push on it past the click with a bit more force it will respond. They swapped the hardware and same thing occurred.
    HP should be ashamed that they would put such awful mouse hardware on its flagship product. Whoever designed it should be fired.
    If HP had any customer loyalty they would offer a hardware update and offer it to those who are still under warranty.
    Suffice to say I will never, ever purchase an HP workstation again.
    Good luck.

  • 0 down vote favorite share [fb] share [tw]        How to hide cut/copy/paste/Replace- menu on the UIWebView when it is being displayed over the keyboard.  Detail: I am having a HTML from, having text box, displayed using UIWebView. If user types in text b

    How to hide cut/copy/paste/Replace… menu on the UIWebView when it is being displayed over the keyboard.
    Detail: I am having a HTML from, having text box, displayed using UIWebView. If user types in text box it shows the keyboard. Now If user tap and hold on text box it shows a popup menu. Now while keyboard and pop up are being displayed user scrolls the view. At this time it shows pop up over the keyboard which I need to hide.
    I tried setMenuVisible of UIMenuController when popup rect and keyboard rect intersects each other on viewDidScroll but it didn't help me.
    Any clues will help a lot.
    Thanks.

    You are more likely to get an answer if you post programming problems to the Developer forum. This forum is intended for normal user level problems.

  • Problem of cut,copy,past ,undo and redo actions

    hi
    iam a student of computer science
    iam working on my project notpad
    in this i have to apply the command of doing cut ,copy ,past ,undo,redo
    how can i use thes actions in my project
    please help me for making my project
    i will wait your response at [email protected]

    what u can do is
    just component.cut();
    or
    compoennt.copy();
    component.paste();
    for undo and redo
    u need to take help of undo manager
    which will tell u whether u can undo or not
    same with redo case
    hope it will work

  • I can't upload or import videos from my iphoto library, into final cut pro x.  When i click, IMPORT MEDIA in FCP, It lists iPhoto Library as GRAY, and will not let me access it.  I need the videos out of there.  I have tried every way I can think of.

    Like the title says...
    I can't upload or import videos from my iphoto library, into final cut pro x.  When i click, IMPORT MEDIA in FCP, It lists 'iPhoto Library' as GRAY, and will not let me select it.  I need the videos out of there.  I have tried every way I can think of.
    I have also tried from the iphoto side, to export the videos or share them to final cut.  I have had no luck.
    I have tried to drag and drop indidual video clips from iphoto to fcp, and the programs simply do not respond to each other
    I can see in the OLDER version of final cut pro x, where it has IMPORT FILES as an option, it was possible.  I see this on forums and youtube videos of the older versions.
    However, the newer version that i have, does not have IMPORT 'FILES' as an option, it is simply all lumped together as IMPORT 'MEDIA'
    Thank You for the Help

    at the end, you say "import preferences", which program are you describing?
    So im safer using footage that is remotely being pulled from iphoto...
    vs
    using footage that is imported into FCP from imovie?
    Is there anything i can do in fcp to make this footage more reliable or safer or more stable as i pull remotely from iphoto?
    All the footage, and all the libraries to all programs, or on a new pegasus 12tb raid 5 setup fyi.

  • Need when right click

    Hi friends,
    my requirement is like this.
       i have  notification number. when right click on that  i need to show select ,move ..
    any body have answer pls let me know
    it's urgent...
    ex :in edit right clik u will get select,move.
    same i need when i have notification number when right click  i have to show move and select

    Hi,
    Context Menus
    The user interface of a screen is defined by a GUI status, which you define in the Menu Painter and assign the type Dialog status. For each dialog status, the system
    automatically creates a standard context menu, which the user can display by clicking the righthand mouse button on the screen (or choosing Shift+F10). The standard context menu contains all of the function keys to which functions are assigned. It therefore makes it easy to access any function code that is available using the keyboard, since normally only the most important are assigned to the application toolbar.
    However, as well as the standard context menu, you can define context-specific menus for any of the following screen elements:
      Input/output fields
      Text fields
      Table controls
      Group boxes
      Subscreens
    When you select one of these elements using the right-hand mouse button, you can create a dynamic context menu in the ABAP program. This may contain any functions, and is not
    restricted to function keys. You cannot assign context menus to pushbuttons, checkboxes, or radio buttons. However, you can assign unique function codes to them instead.
    Example
    The following example shows some of the technical possibilities for creating context menus, but
    does not necessarily observe all of the style guidelines.
    REPORT demo_dynpro_context_menu.
    DATA: field1 TYPE i VALUE 10,
    field2 TYPE p DECIMALS 4.
    DATA: prog TYPE sy-repid,
    flag(1) TYPE c VALUE 'X'.
    DATA: ok_code TYPE sy-ucomm,
    save_ok TYPE sy-ucomm.
    prog = sy-repid.
    CALL SCREEN 100.
    MODULE status_0100 OUTPUT.
    SET TITLEBAR 'TIT100'.
    IF flag = 'X'.
    SET PF-STATUS 'SCREEN_100' EXCLUDING 'REVEAL'.
    ELSEIF flag = ' '.
    SET PF-STATUS 'SCREEN_100' EXCLUDING 'HIDE'.
    ENDIF.
    LOOP AT SCREEN.
    IF screen-group1 = 'MOD'.
    IF flag = 'X'.
    screen-active = '1'.
    ELSEIF flag = ' '.
    screen-active = '0'.
    ENDIF.
    MODIFY SCREEN.
    ELSEIF screen-name = 'TEXT_IN_FRAME'.
    IF flag = 'X'.
    screen-active = '0'.
    ELSEIF flag = ' '.
    screen-active = '1'.
    ENDIF.
    MODIFY SCREEN.
    ENDIF.
    ENDLOOP.
    ENDMODULE.
    MODULE cancel INPUT.
    LEAVE PROGRAM.
    ENDMODULE.
    MODULE user_command_0100.
    save_ok = ok_code.
    CLEAR ok_code.
    CASE save_ok.
    WHEN 'HIDE'.
    flag = ' '.
    WHEN 'REVEAL'.
    flag = 'X'.
    WHEN 'SQUARE'.
    field2 = field1 ** 2.
    WHEN 'CUBE'.
    field2 = field1 ** 3.
    WHEN 'SQUAREROOT'.
    field2 = field1 ** ( 1 / 2 ).
    WHEN 'CUBICROOT'.
    field2 = field1 ** ( 1 / 3 ).
    ENDCASE.
    ENDMODULE.
    Callback-Routines
    FORM on_ctmenu_text USING l_menu TYPE REF TO cl_ctmenu.
    CALL METHOD:l_menu->load_gui_status
    EXPORTING program = prog
    status = 'CONTEXT_MENU_1'
    menu = l_menu.
    ENDFORM.
    FORM on_ctmenu_frame USING l_menu TYPE REF TO cl_ctmenu.
    CALL METHOD:l_menu->load_gui_status
    EXPORTING program = prog
    status = 'CONTEXT_MENU_2'
    menu = l_menu,
    l_menu->load_gui_status
    EXPORTING program = prog
    status = 'CONTEXT_MENU_1'
    menu = l_menu,
    l_menu->set_default_function
    EXPORTING fcode = 'HIDE'.
    ENDFORM.
    FORM on_ctmenu_reveal USING l_menu TYPE REF TO cl_ctmenu.
    CALL METHOD:l_menu->load_gui_status
    EXPORTING program = prog
    status = 'CONTEXT_MENU_3'
    menu = l_menu,
    l_menu->load_gui_status
    EXPORTING program = prog
    status = 'CONTEXT_MENU_1'
    menu = l_menu,
    l_menu->set_default_function
    EXPORTING fcode = 'REVEAL'.
    ENDFORM.
    FORM on_ctmenu_input USING l_menu TYPE REF TO cl_ctmenu.
    DATA calculate_menu TYPE REF TO cl_ctmenu.
    CREATE OBJECT calculate_menu.
    CALL METHOD: calculate_menu->add_function
    EXPORTING fcode = 'SQUARE'
    text = text-001,
    calculate_menu->add_function
    EXPORTING fcode = 'CUBE'
    text = text-002,
    calculate_menu->add_function
    EXPORTING fcode = 'SQUAREROOT'
    text = text-003,
    calculate_menu->add_function
    EXPORTING fcode = 'CUBICROOT'
    text = text-004,
    l_menu->add_submenu
    EXPORTING menu = calculate_menu
    text = text-005.
    ENDFORM.
    Regards,
    Bhaskar

  • Undo/Redo for Cut, Copy, Paste

    I am trying to implement Undo/Redo for Cut,Copy,Paste in a Treetable.
    I have to support undo/redo for multiple nodes being cut/copied. I am not sure how I should be going about implementing this. Any help will be greatly appreciated.
    Thanks

    If the class you are using doesn't support cut, copy, and paste already, usually what you do is store a list of actions in two lists. One for actions done, the other for redos (when there is an undo). Capture the data before and after each operation (you can create a KeyListener to listen for the events) and store that in a list. When undo is called, the last element on the list should be undone, either by taking it out of the list and reiterating through the elements still there, or implementing an undo method in the object you are trying to change. Then put that element on the redo list in case that is called. This works well with graphics and stuff, but I never tried to implement it in a tree with nodes and stuff, so that's about the most I can help with right now. I hope it helps some!
    -JBoeing

  • Jeditor pane cut, copy, paste

    I have an applet using jeditor panes. when you right click a popup shows and you can choose to cut, copy, paste, select all. I use the functions copy, cut, paste, selectAll which jeditorpane inherits. This works properly in java 1.3X but in java 1.41 it is not working. Is there cliboard communication problems with java 1.41?

    Hi dhhyde,
    If you are having issues with your cutting, copying and pasting items from your iPad, you may want to try some things to troubleshoot.
    First, quit all running applications and test again -
    iOS: Force an app to close
    Next, I would try restarting the iPad -
    Turn your iOS device off and on (restart) and reset
    If the issue is still present, you may want to restore the iPad as a new device -
    How to erase your iOS device and then set it up as a new device or restore it from backups
    Thanks for using Apple Support Communities.
    Best,
    Brett L  

  • Cut,copy,paste in jtextfield

    Hi,
    I gotta JTextField. Now I want to get a popup menu when i right-click it to ask me if i wanna cut, copy or paste using the default os clipboard.
    can anyone suggest me any helpful url ?

    Clipboard operations such as copy, cut and paste are very easy to perform on a JTextField. Just use the JTextField's void cut(), copy() and paste() methods! That's all there is to it.
    In this demo I wrote, I've shown how to use these methods, and how to create a JPopupMenu menu that appears when the user right-clicks on the JTextField, showing the three clipboard functions.
    Enjoy!
    import java.awt.*;
    import java.awt.datatransfer.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ClipboardDemo extends JFrame implements ActionListener {
         JPanel mainPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
         JLabel descrLabel = new JLabel("Clipboard Demo by Ben James");
         JTextField theTextField = new JTextField(20);
         final JPopupMenu clipboardMenu = new JPopupMenu();
         JMenuItem cutMenuItem = new JMenuItem("Cut");
         JMenuItem copyMenuItem = new JMenuItem("Copy");
         JMenuItem pasteMenuItem = new JMenuItem("Paste");
         public ClipboardDemo() {
              super("Clipboard Demo");
              theTextField.setText("Highlight some text and right-click!");
              cutMenuItem.addActionListener(this);
              copyMenuItem.addActionListener(this);
              pasteMenuItem.addActionListener(this);
              clipboardMenu.add(cutMenuItem);
              clipboardMenu.add(copyMenuItem);
              clipboardMenu.add(pasteMenuItem);
              theTextField.addMouseListener(new MouseAdapter() {
                   public void mouseReleased(MouseEvent evt) {
                        if (evt.isPopupTrigger()) {
                             clipboardMenu.show(evt.getComponent(), evt.getX(), evt.getY());
              mainPane.add(descrLabel);
              mainPane.add(theTextField);
              mainPane.setPreferredSize(new Dimension(250,75));
              WindowListener wl = new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
                        System.exit(0);
              setContentPane(mainPane);
              addWindowListener(wl);
              pack();
              setResizable(false);
              setVisible(true);
         public void actionPerformed(ActionEvent evt) {
              Object source = evt.getSource();
              if (source == cutMenuItem) {
                   theTextField.cut();
              if (source == copyMenuItem) {
                   theTextField.copy();
              if (source == pasteMenuItem) {
                   theTextField.paste();
         public static void main(String[] args) {
              ClipboardDemo cd = new ClipboardDemo();
    }

  • How do I reinstall the edit button on my Firefox 4 toolbar; cut, copy, paste, and print?

    I recently have been having problems with my Firefox 4 tool bars. Right now, the Edit icons are no longer on the tool bar, specifically Cut, Copy, Paste, and Print. If there were other Edit icons, they too are gone. All the other icons have remained.
    I would appreciate it if you could advise me how to reinstall those specific icons.
    Also recently, ALL my tool bars, and task and status bar disappeared. This was only in Firefox 4.0; IE 8 was not affected. Clicking F11 did not work. I could not function without them. Then, a short time later, they "automatically" reappeared. I have not idea of why the disappeared or reappeared.
    Thank you for any help you can provide.
    Sanford A. Berman

    You can find the Copy, Paste, and Cut buttons next to Firefox > Edit (and in its sub menu) and in the regular Edit menu on the menu bar (press F10 if the menu bar is hidden).
    The buttons next to Firefox > Edit are enabled if there is something to do with them, just like with the toolbar buttons.
    You can find the Copy, Paste, and Cut toolbar buttons in the toolbar palette in the Customize window and drag them on a toolbar.
    Open the Customize window via "View > Toolbars > Customize" or via "Firefox > Options > Toolbar Layout"
    *http://kb.mozillazine.org/Toolbar_customization
    *https://support.mozilla.com/kb/Back+and+forward+or+other+toolbar+items+are+missing

  • Image selection,cut,copy,paste

    Hi,
    I need to select a portion of the graphics thats been drawn on a panel,
    cut this image,copy and paste it on any part of the panel. I have tried using clipRect but am not sure whether this will work.
    Please help me doing the cut,copy,paste of these images. It would be nice to have a sample code.
    Arpana

    Since your question is to learn and understand how Illustrator works, I would answer it with no. Unlike other programs, Illustrator can't cut parts of raster images because it is mostly vector graphics editing program. It is possible to end up with a rectangular shape of a cut raster images using the method Jacob described but technically behind the scenes it is not cutting the raster image as other raster programs like Photoshop do but it is generating a new image from the old one by a capability in Illustrator called rasterizing. Illustrator can rasterize (regenerate a new raster image) from any selection of objects - vector, raster, and both at a specified resolution using commands like Rasterize and Flatten Transparency. You can think of it as automating the process of exporting to a raster file format and placing it back in Illustrator.
    For that reason, I would recommend to cut raster images in other programs like Photoshop and place them in the desired size in Illustrator or use clipping paths and Opacity masks to hide unwanted parts  when this is preferable for flexibility or if you find it faster and less hassle than cutting the placed image outside of Illustrator.

  • HT1203 I have an account which is shared with 3 computers. I have managed to get all files on Itunes. I have made a new playlist and when right clicked I pressed Download. Will this charge me again?

    I just need to know if i pressed "download" when right clicking the playlist on the new authorised computer, is this charging me again?
    Could you please help?!
    Elvy

    Hi Elvy,
    It sounds like you may have just downloaded the purchase again through iTunes in the Cloud:
    iCloud - iTunes in the Cloud
    http://www.apple.com/icloud/features/itunes-in-the-cloud/
    Your past purchases. Available on all your devices.
    Now you can download music, movies, and TV shows you’ve previously purchased to all your devices. When you buy from iTunes, iCloud stores your purchase history. So you can see what you’ve bought — no matter which device you bought it on. You can access your purchase history from the iTunes Store on your iPhone, iPad, iPod touch, Mac, PC, or Apple TV. Since you already own the songs, albums, movies, or TV shows in your purchase history, you can tap to download them to any of your devices.1 And whenever you play a movie, TV episode, podcast, iTunes U lesson, or audiobook on one device, all your other devices will automatically remember where you left off. Just sign in to the iTunes Store with your Apple ID.
    I hope this helps!
    - Ari

  • Enabling/Disabling Cut/Copy/Paste buttons

    Here's today's "Tear My Hair Out" problem.
    I'm working on a data manipulation application, where we will be providing the standard cut/copy/paste functionality. We want to disable the menu items and toolbar buttons if there's nothing selected. I know this is possible, since both JDeveloper and NetBeans do it, but I'm at a loss for a clean way to do it.
    The only thing I can come up with is to add key, mouse, and focus listeners to each text component and check the selection whenever an appropriate event happens which could affect it. Obviously a lot of overhead.
    Anyone know a simpler way to do this?
    Thanks.

    Check out the Clipboard class, and the getSystemClipboard() method in Toolkit (I think).
    If you were to store your data on the system clipboard, like most applications, then you can have a single thread which monitors the state of the clipboard and updates the state of the paste button as and when is appropriate.
    Alternatively, use your own clipboard. Just so long as there is ONE resource which stores all the cut/copy data, and changes the state of the paste button accordingly.
    For the cut/copy actions, you will probably have only one method which carries this out, so have this method update the state of the cut/copy buttons.
    This really is very simple. If it's getting too complicated, you're doing it wrong. Hope this helps.

Maybe you are looking for

  • Runtime report generation from legacy Sales tool

    My organization (IT) is looking to move the runtime contract/invoice reporting from an existing product and service sales tool (contracts and invoices are produced for the customer) to an environment where report template design and ownership can be

  • How to establish two ethernet connections simultaneously?

    Hi! I have a two-ports router. The first port via ordinary RG-45, and the second port via usb interface. I want to have both of them to be connected simultaneously. I done this at Gentoo, but can't to do at Arch. So, what I done exactly: I found and

  • Connecting to mySQL database, timeout error

    I am having problems connecting to my database, here is the connection class public class DBConnect     public static Connection getDBConnect() throws Exception         String x = "worked";         //String url = "jdbc:mysql://mysql8.secureserver.net

  • Losing comments when moving markers

    when i add comments to various fields while logging captured video, i then move the markers to a new folder, creating sub-clips... why does doing this cause me to lose the comments i've made in various fields, many customized and saved/loaded to matc

  • JPOUG Tech Talk Night #3 - 2013年11月12日(火)19:00@OAC

    2013年11月12日(火)19:00オラクル青山センターにて JPOUG Tech Talk Night #3 を開催します. 今回はOracle Corporation Database Upgrade Groupの Senior Director Software Dev. & Product Managerである Roy Swongerさんと Senior Principal Technologistの Mike Dietrichさんから"Upgrade, Migrate and Con