Results 1 to 4 of 4
  1. #1
    quito is offline Member
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default add popupmenu with copy/paste/cut to 4 textfields

    I would like to add popupmenu with copy/paste/cut to 4 textfields so I have code:

    Java Code:
    private void jTextField1MousePressed1(java.awt.event.MouseEvent evt) {                                         
            if (evt.isMetaDown()) {   
                jPopupMenu1.show(evt.getComponent(), evt.getX(), evt.getY());
                jPopupMenu1.setInvoker(evt.getComponent());
            } 
    }       
    
    private void jTextField2MousePressed(java.awt.event.MouseEvent evt) {
            if (evt.isMetaDown()) {   
                jPopupMenu1.show(evt.getComponent(), evt.getX(), evt.getY());
                jPopupMenu1.setInvoker(evt.getComponent());
            } 
        }
    
        private void jTextField3MousePressed(java.awt.event.MouseEvent evt) {
            if (evt.isMetaDown()) {   
                jPopupMenu1.show(evt.getComponent(), evt.getX(), evt.getY());
                jPopupMenu1.setInvoker(evt.getComponent());
            } 
        }
    
    private void jTextField4MousePressed(java.awt.event.MouseEvent evt) {
            if (evt.isMetaDown()) {  
                jPopupMenu1.show(evt.getComponent(), evt.getX(), evt.getY());
                jPopupMenu1.setInvoker(evt.getComponent());
            } 
        }
    And action for each menuitem in popupmenu:
    Java Code:
    private void jMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
            Object source = evt.getSource(); 
            if (source == jMenuItem1) {
                    JTextField jte = (JTextField)jPopupMenu1.getInvoker();
                    jte.copy();
            }
            else if (source == jMenuItem2) {
                    JTextField jte = (JTextField)jPopupMenu1.getInvoker();
                    jte.copy();
            }
            else if (source == jMenuItem3) {
                    JTextField jte = (JTextField)jPopupMenu1.getInvoker();
                    jte.copy();
            }
        }
    I see popupmenu with copy/paste/cut but it doesn't work - I can't for example copy -why?

  2. #2
    chipp's Avatar
    chipp is offline Member
    Join Date
    Jul 2011
    Posts
    62
    Rep Power
    0

    Default Re: add popupmenu with copy/paste/cut to 4 textfields

    i'm a newbie in java, so my following opinion probably wrong.

    OOT: why you don't use a single function for all your event handlers?

    Java Code:
    private void jTextField1MousePressed1(java.awt.event.MouseEvent evt) {                                         
            handlers();
    }       
     
    private void jTextField2MousePressed(java.awt.event.MouseEvent evt) {
            handlers();
    }
     
    private void jTextField3MousePressed(java.awt.event.MouseEvent evt) {
            handlers()
    }
     
    private void jTextField4MousePressed(java.awt.event.MouseEvent evt) {
            handlers (); 
    }
    
    public void handlers () {
            if (evt.isMetaDown()) {  
                jPopupMenu1.show(evt.getComponent(), evt.getX(), evt.getY());
                jPopupMenu1.setInvoker(evt.getComponent());
            }
    }

  3. #3
    quito is offline Member
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Re: add popupmenu with copy/paste/cut to 4 textfields

    Ok i know - in each IF I have jte.copy() - lol :P It should be: copy(), paste() and cut() :P
    Last edited by quito; 05-12-2012 at 02:25 PM.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

Similar Threads

  1. cut/copy/paste in JTextField
    By gauravmanral in forum AWT / Swing
    Replies: 14
    Last Post: 09-25-2011, 07:07 AM
  2. JTable copy and paste problem on Mac
    By willlotr in forum AWT / Swing
    Replies: 4
    Last Post: 04-07-2011, 07:15 PM
  3. Copy, Cut and Paste Problems!
    By bones in forum New To Java
    Replies: 4
    Last Post: 07-17-2009, 10:18 AM
  4. Cut, copy and Paste in JTextPane
    By Gudradain in forum AWT / Swing
    Replies: 1
    Last Post: 01-03-2009, 06:43 AM
  5. Problems with copy paste
    By fredand44 in forum Eclipse
    Replies: 0
    Last Post: 12-17-2008, 04:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •