Right Click JTextField cut copy paste

In this post you can learn an example on how to implement right click option for cut, copy and paste in a JTextField in java swings. This concept is used in many swing application development.

      JTextField textfield;
      textfield = new JTextField(15);
    
      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);

No comments:

Post a Comment

My Profile