How to activate mouse right click in JTexhArea

Hi Swings Expert!
I've a problem to get action mouse right click in JTextArea for example to cut and paste selected text from textarea into another textarea.
If I want to copy and paste text from textarea, Ive to use Ctrl C for copy
and Ctrl V for paste the selected text.
Is there a way to activate mouse right click in JTextArea?
any help.....Thanks a lot.

Here are the basics:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class PopupMenuTest extends JFrame implements MouseListener
     public JPopupMenu popup;
     public PopupMenuTest()
          popup = new JPopupMenu();
//          popup.add( new DefaultEditorKit.CutAction() );
          JMenuItem item = new JMenuItem( new DefaultEditorKit.CutAction() );
          item.setMnemonic('C');
          popup.add( item );
          popup.add( new DefaultEditorKit.CopyAction() );
          popup.add( new DefaultEditorKit.PasteAction() );
          JTextField textField = new JTextField("Right Click For Popup");
          textField.addMouseListener( this );
          getContentPane().add(textField);
     private void checkForPopup(MouseEvent e)
          if (e.isPopupTrigger())
               popup.show(e.getComponent(), e.getX(), e.getY());
     public void mousePressed(MouseEvent e)
          checkForPopup( e );
     public void mouseReleased(MouseEvent e)
          checkForPopup( e );
     public void mouseClicked(MouseEvent e) {}
     public void mouseEntered(MouseEvent e) {}
     public void mouseExited(MouseEvent e) {}
     public static void main(String[] args)
          PopupMenuTest frame = new PopupMenuTest();
          frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
          frame.pack();
          frame.setLocationRelativeTo( null );
          frame.show();
}

Similar Messages

  • How to activate mouse right click  on a JTree PATH

    Hi,
    I'm trying to generate a pop menu in a Jtree on mouse event right click.
    So far it is okay, but the problem I have now is to popup the menu only if a precise element of the Jtree is selected.
    Here is some pieces of my code :
    private void fill_panelCenter() {
    stmt.init(conn.getconn());
    ttree.build_root(racine, stmt.getTables(), stmt.getViews(), stmt.getIndexes(), stmt.getPackages(), stmt.getProcedures(), stmt.getFunctions());
    NewTree = new JTree(ttree.getracine());
    NewTree.setBounds(new Rectangle(0, 0, 288, 677));
    trexTree.setVisible(false);
    NewTree.setVisible(true);
    NewTree.addTreeSelectionListener(new TreeSelectionListener(){
    public void valueChanged(TreeSelectionEvent e)
    popup.add("Edit");
    NewTree.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    NewTree_mouseClicked(e);
    jScrollPane1.getViewport().add(NewTree, null);
    panelCenter.add(jScrollPane1, null);
    private void NewTree_mouseClicked(MouseEvent e) {
    if (e.get && e.getButton() == 3) {
    popup.show(e.getComponent(), e.getX(), e.getY());
    }

    Hi,
    Thanks for tip, well i didn't use exactly what was there but it help me
    make my own.
    And i find it a bit more simple so for anybody who that might help :
    NewTree.addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent e) {
    if (e.getButton() == 3) {
    TreePath path = NewTree.getPathForLocation(e.getX(), e.getY());
    if (path != null) {
    popup.show(NewTree, e.getX(), e.getY());
    Remember to replace NewTree by your own !
    :-D
    Well well I just need to make the path selected now .... I mean after the right click so the user knows which path he has selected.
    Any ideas ?

  • How to increase mouse right click refresh rate

    f

    Hi there @manoj1458 
    Welcome to the HP Support Forums! It is a great place to find the help you need, both from other users, HP experts and other support personnel.
    I understand you want to adjust the response for your mouse. I am happy to help with this.
    I would start with looking through the following which allows you to make several adjustments, otherwise try the second page on troubleshooting.
    HP PCs - Mouse Features and Settings (Windows 8)
    HP PCs - Troubleshooting Mouse Problems (Windows 8)
    If you are still having trouble please provide some more detail as to what is happening so I can be more precise in my support.
    Malygris1
    I work on behalf of HP
    Please click Accept as Solution if you feel my post solved your issue, it will help others find the solution.
    Click Kudos Thumbs Up on the right to say “Thanks” for helping!

  • How to catch mouse right click?

    isRightMouseButton(MouseEvent) is not recognized
    by the compiler. What shall I import to get isRightMouseButton()
    pass the compiler? Thank you. (I did have
    javax.swing.*; and javax.swing.event.*)

    Right...note that Java 1.5 supports static imports
    that solve this exact issue.If you think it's an issue that needs resolving, that is. I think it's just asking for less-readable code.

  • Mouse Right Click

    Hello all,
    How to track mouse right click in Oracle Forms? I have a form which has a popup menu, based on the item status i have to enable and disable some options in the popup menu. Any ideas?
    With Regards,
    Yathish

    try the PRE-POPUP-MENU - trigger

  • Facing Strange Problem in DIR HOW TO DISABLE THE RIGHT CLICK MOUSE IN THE DIRECTOR? (through parent script/ movie?)

    Summary : HARD QUESTION : In the DIR file, the game runs well, right click = no effect. Coz I'm not making right click scripts. BUT in EXE file, right click = ERROR.
    Explanation :
    In the Adobe Director screen, this DIR file game is worked 100%.
    I tested right click EVERYWHERE... NOTHING HAPPENS.
    Because I don't make any programming with "on rightmouseup" or "on rightmousedown" command.
    THEN, I published it into EXE...
    I tested right click EVERYWHERE...I hoped the result will be the same as DIR tests....
    WHEN I RIGHT CLICK IN THE AREA THAT'S GIVEN ON EXITFRAME ME, IT SHOWS ERROR, CHANGING PICTURES.....
    this does not happened in the DIR file...
    I didn't make a runmode program or anything else.... This is awkward... mystery for me...
    WHY THERE'S A DIFFERENCE IN DIR and EXE... it should be exactly the same result.
    I have used Director for years.... This is really strange for me...
    >>>>>>>>HOW TO DISABLE THE RIGHT CLICK MOUSE IN THE DIRECTOR?
    THIS ONE is useless.... It doesn't prevent the rightmouse click,...
          on rightmouseup me
                 nothing
         end
          on rightmousedown me
                 nothing
         end

    Dear Adobe Forums friends
    I need your help and guide through this problem...
    In the game's dir file that is run on the DIRECTOR softwawre,
    the game runs perfectly, I can do LEFT CLICKS (coz I programmed the script)
    and when I do RIGHT CLICKS = there are no effect ( coz I don't do script for it)
    LATER THIS GAME TURNED INTO EXE.
    It supposed to run like the dir file as ABOVE. BUT STRANGELY, WHEN
    I DO RIGHT CLICKS, it turns Error and showing as the picture attachment.
    The right clicks that goes error are above the picture of numeric button only. (in DIR file
    this run normal). I looked into the script behind the numeric button picture, there are only "on exitframe me", there are no script I made inside the "on exitframe me" that is triggering RIGHT CLICKS.
    1. I wonder why there are differences in DIR and EXE effect
    2. Why right click? Left click effects are all normal.
    3. IS THERE ANY WAY TO DISABLE ALL RIGHT CLICKs since the beginning of EXE. So the game will be run normal. I don't need right clicks anyway, but whenever people do right click there will be ERROR.??
    4. Is there any way to STOP THE MESSSAGE BOX TO APPEAR IN FRONT OF THE GAME? (I hate the Dirrector Error Message Box), or auto press OK.
    NB: this game uses Buddy API Xtras, File IO Xtras.
    Thx
    David S

  • How write Vbscript for Mouse Right Click using UFT 11.5

    how write Vbscript for Mouse Right Click using UFT 11.5

    Press and hold the Control (Ctrl) key while you click the mouse button. This is identical to right-clicking with a mouse. (Ctrl+click = Right click)
    You can try the following:
    •Click on and off the 'right click' checkbox in the Mouse System Preferences
    •Restart in Safe Mode
    •Reset NVRAM / PRAM

  • Mouse right-click function doesn't work in Bookmarks (Mac)

    I recently switched from PCs to Macs. No problem downloading Firefox and transferring old bookmarks and other settings, with one exception. With the PCs, when I right-clicked a particular bookmark under Bookmarks I got a series of 12 options (from Open, Open in New Window to Delete, Sort by Name, Properties). I used these a lot to delete bookmarks, change names, alphabetize lists, etc. I can now do most of these things under the Manage Bookmarks setting, but when I right click bookmarks now the new bookmark I click on just replaces the one on screen (ie, the right click does exactly what the left click does). I am using two different mice (Apple Mighty Mouse with Leopard, Microsoft Wheel Mouse with Tiger) and the right click function behaves as expected in other programs. Are these mouse right click Bookmark functions supposed to appear with the Firefox for Mac? If so, any ideas how to resolve my problem?

    Can someone explain to me why it's possible in Chrome on Mac, but not on Firefox? This is my 2nd biggest complaint about FF on the Mac, only surpassed by missing favicons in bookmarks. Chrome does both very well.

  • Apple mouse right click function stopped working

    After 4 and a half years my Apple mouse right click function on my iMac stopped working.  However the mouse works perfectly on my other iMac.  The apple store said the problem is in the iMac.  Any ideas how to fix this?
    Thanks, jpm3577

    First log into another user account on your Mac and see if it work correctly there.  If not boot into Safe Mode, Mac OS X: Starting up in Safe Mode, and try there.  Also try another USB port on the Mac if it's a wired mouse.

  • Mouse right click won't work

    Just bought a new imac.  I cannot figure out how to set up right click on my mouse. I have searched the internet high and low and found exactly how it is supposed to be done in system preferences.  When I go to mouse in system preferences, there is no option to set up right click or secondary click.  I am on OS X 10.7.2.  My frustration abounds.  Help me please!

    Problem solved.  Needed to click on "point & click" button in mouse preferences.  Well, at least I was not the only dolt that had this problem.

  • The control click and external mouse right click no longer works when copying and pasting album art within itunes. Ex. Hit get info for one song to paste to the rest, copying the artwork wont work when it used to.

    The control click and external mouse right click no longer works when copying and pasting album art within itunes. Ex. Hit get info for one song to paste to the rest, copying the artwork wont work when it used to.

    Hello there, Teworsham90.
    The following Knowledge Base article reviews the process of adding artwork to content in your iTunes Library:
    iTunes: How to add artwork to songs and videos in your library
    http://support.apple.com/kb/HT1409
    Thanks for reaching out to Apple Support Communities.
    Cheers,
    Pedro D.

  • JPopupMenu - disabling mouse right click

    Hi,
    First of all, before I write the problem here, I searched a lot but I actually could not find the desired solution.
    The problem is;
    I have a JPopupMenu. As you know, all mouse clicks (left click, middle click and right click) do the selection in popup menu and then it tries to perform the related action. Finally, the popup menu disappears. But, what I want actually is that "my popup menu will not respond to the mouse right click and will not disappear after that right click".
    Can anyone say how to make that happen?
    Thanks a lot.

    The following is an example code, and I did not the details of how the popup menu showed. I just showed how the actions are added to the popup menu elements. In this example, in the popup menu there are Text1, Text2 and Text3 selections and their actions are added like in the code. So, my actions are seperate for each element in the popup menu. Now, how can I make the mouse right click will not enter the related selection's actionPerformed (e.g; Text1, Text2) and the popup menu will not disappear?
    public class JPopupMenuTest {
        public static void main(String[] args) {
            JPopupMenuTest popupTest = new JPopupMenuTest();
            JPopupMenu popupMenu = new JPopupMenu();
            popupMenu.add(popupTest.new Text1Action());
            popupMenu.add(popupTest.new Text2Action());
            popupMenu.add(popupTest.new Text3Action());
        class Text1Action extends AbstractAction {
            public Text1Action() {
                super("Text1");
            @Override
            public void actionPerformed(ActionEvent e) {
                // Here is the Text1 action performed
        class Text2Action extends AbstractAction {
            public Text2Action() {
                super("Text2");
            @Override
            public void actionPerformed(ActionEvent e) {
                //  Here is the Text2 action performed
        class Text3Action extends AbstractAction {
            public Text3Action() {
                super("Text3");
            @Override
            public void actionPerformed(ActionEvent e) {
                // Here is the Text3 action performed
    }

  • Robot mouseClick with mouse right click

    I try to capture mouse right click and fire mouse right click event in robot.mousePress or mouseRelease.
    does anybody know how to do this?
    Thanks.

    rocketlad
    Welcome to the forum. Please don't post in threads that are long dead. When you have a question, start your own topic. Feel free to provide a link to an old post that may be relevant to your problem.
    I'm locking this thread now.
    db

  • X130e - "mouse right click " short cut on keyboard

    I just bought Thinkpad x130e
    I desperately need "mouse right click " shortcut on my keyboard, I am soo use it....
    May I know how can i get on my keyboard ?
    all other leading brands has this shorcut key on their laptop's keyoard ! I am really shocked Thinkpad series doesn't have this, 
    is there a way to Remap ???
    Regards 
    Shahnmn

    Good Morning,
    Try hitting shift and F10 at the same time is how you right click. 
    This should work.
    Serge E. Minott

  • Prevent Mouse right click

    Hi all,
    In web browser how can we prevent the mouse right click for our web pages
    regards,
    Mahe

    edng wrote:
    you guys are funny
    you can prevent someone from right click the mouse. i've seen web pages implementing this feature. when you right click, it says 'this function is disabled'
    its no different than people streaming and when you right click on the stream you get nothing cause its block so you cannot tell the properties etcNot really, it only gives the illusion that it was disabled. You could possibly turn off Javascript to enable it. You could use another browser that does not support this "feature" or gives you more control. You could used greasemonkey as pm_kirkham said.
    The point is that all the things that appear to happen are only because Internet Explorer (or whatever) allow the �feature�. If your code relies on browser tricks to be valid then the code is broken. Browser edits, etc. should only be used to make the application more user-friendly but should work even if the features are not available in the browser.

Maybe you are looking for

  • How to sum the revenue based on new dimensional attribue?

    Experts, I have a requirement in which I want to report the monthly revenue based on a new attribue named cusotmer group. My existing customer dim hierarchy is something like this.. customer_id -> customer_family -> Customer Segment -> Total Customer

  • Can't view thumbnails or edit  recently uploaded photos.

    In the last few rolls that I uploaded from my camera, the photos do not show up as thumbnails. I can see the photos if I choose "show file" but these can only be viewed in Preview and not in iPhoto. I have tried to copy them back into iPhoto but the

  • ERROR Could not open [xmllog4jconfig.xml]

    I created a project under JDeveloper that includes an XML file that I created. The project compiles fine. But, when I try to run the project, I get the following Error message: java.io.FileNotFoundException: xmllog4jconfig.xml (The system cannot find

  • Change ReplyTo in WS-Addressing Header

    Hi, i have created an async webservice with JAX-WS and i want to consume this by using BPEL. All works fine with correlationSet. But in the SOAP-Header the ReplyTo-Address is wrong. <addr:ReplyTo xmlns:addr="http://www.w3.org/2005/08/addressing"> <ad

  • Java 2 SE 1.3.1 and XP

    I'm hearing that the Java plug-in 1.3.1 is not compatible (will not work) with Windows XP. Is this true? Any solutions? I'm upgrading to XP in part, due to a fairly serious memory leak problem in Windows ME, of which there is no fix at the moment. At