Fire a left click when the right button is pressed

I am working on a small program with a text area and mouse functionality. I have all my listeners in place but I need one additional feature and I am unsure how to go about implementing it. I want to be able to fire a left click when the right button is pressed.
The reason is because right clicking does not move the caret around the text area. I need to be able to move the caret with a right click so I can then invoke another method to do some other functionality that is associated with the right click. Any method is acceptable as long as a right click will result in the caret being able to move to a location much like a left click can.
all help is appreciated. Thanks.

I'm not sure if this is "better", and my guess is that it isn't, but how about using a Robot object here to create a left mouse press and release? For instance,
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class RightClickAsLeft
  private JPanel mainPanel = new JPanel();
  private JTextArea area = new JTextArea(20, 50);
  private Robot robot;
  public RightClickAsLeft()
    try
      robot = new Robot();
    catch (AWTException e)
      // TODO Auto-generated catch block
      e.printStackTrace();
    mainPanel.add(new JScrollPane(area));
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < 18; i++)
      for (int j = 0; j < 80; j++)
        sb.append((char)(40 + j));
      sb.append("\n");
    area.setText(sb.toString());
    area.addMouseListener(new MyMouseListener());
  public JComponent getComponent()
    return mainPanel;
  private class MyMouseListener extends MouseAdapter
    @Override
    public void mouseClicked(MouseEvent e)
      int button = e.getButton();
      if (button == MouseEvent.BUTTON3)
        if (robot != null)
          robot.mousePress(InputEvent.BUTTON1_MASK);
          robot.mouseRelease(InputEvent.BUTTON1_MASK);
  private static void createAndShowUI()
    JFrame frame = new JFrame("RightClickAsLeft");
    frame.getContentPane().add(new RightClickAsLeft().getComponent());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  public static void main(String[] args)
    java.awt.EventQueue.invokeLater(new Runnable()
      public void run()
        createAndShowUI();
}Edited by: Encephalopathic on Apr 10, 2009 9:59 AM

Similar Messages

  • IPhone 4s Voice Memo App has 5 second delay when the record button is pressed. When it starts recording, it goes from 0 seconds to 5 or so seconds recorded. This happens randomly and often and sometimes has the delay but starts at zero. Solution Anyone?

    After iOS 7 update, my iPhone 4s Voice Memo App has 5 second delay when the record button is pressed. When it starts recording, it goes from 0 seconds to 5 or so seconds that it shows has recorded. This happens randomly and often, sometimes it will have the 5+ second delay but starts recording at zero seconds. Besides the delay it has been working fine as far as saving and playback is concerned. I have plenty of storage on the phone itself and it NEVER had this problem before I updated to iOS 7. I've reset the phone a couple times by holding down the power and home buttons at the same time. The reason I have an issue with this is that I'm always recording song ideas, melodies, and scratch takes; what I'm saying is when I come up with an idea I need to be able to know that when I hit record it will start right then so I don't forget anything that has just popped in my mind.
    Does anyone have a solution or suggestion?
    Thanks

    After iOS 7 update, my iPhone 4s Voice Memo App has 5 second delay when the record button is pressed. When it starts recording, it goes from 0 seconds to 5 or so seconds that it shows has recorded. This happens randomly and often, sometimes it will have the 5+ second delay but starts recording at zero seconds. Besides the delay it has been working fine as far as saving and playback is concerned. I have plenty of storage on the phone itself and it NEVER had this problem before I updated to iOS 7. I've reset the phone a couple times by holding down the power and home buttons at the same time. The reason I have an issue with this is that I'm always recording song ideas, melodies, and scratch takes; what I'm saying is when I come up with an idea I need to be able to know that when I hit record it will start right then so I don't forget anything that has just popped in my mind.
    Does anyone have a solution or suggestion?
    Thanks

  • I want to upload from my iphone playlist to my laptop (Windows 8) why is it so hard to find the right buttons to press????

    i want to upload from my iphone playlist to my laptop (Windows 8) why is it so hard to find the right buttons to press????

    Review these Knowledge Base articles... they may help you:
    Synchronizing media using BlackBerry Desktop Software on a Mac computer
    BlackBerry Desktop Software Mac does not display evens and albums from iPhoto 9.4.2
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • TS1365 My Macbook Pro 17" 2.44ghz all of a sudden one day decided to not boot up. When the power button is pressed the sleep light in the front on the latch release turns on and there is a small running sound but it never boots up and the screen never lig

    My Macbook Pro 17" 2.44ghz all of a sudden one day decided to not boot up. When the power button is pressed the sleep light in the front on the latch release turns on and there is a small running sound but it never boots up and the screen never lights up. Anyone else have this problem? Any ideas?
    I'd love to repair it but not if it'll cost 500 bucks or more to replace the logicboard.
    I appreciate any help
    Michael

    Lao Bo,
    yes, you can locate and copy a file from your HD to a USB key using UNIX commands. If you know the exact name of the file which you’re trying to locate, try this:
    find / -iname filename -print
    This command will search your entire internal disk for the particular filename. If you know that it’s within a particular user account, then you can save search time with this variation:
    find /Users/username -iname filename -print
    Either variation of this command will print all files found which have the given filename. Presuming that you’re able to identify the correct file, you can copy it to a USB key using the command
    cp -p filename_returned_by_find /Volumes/USB_volume
    If you’re not sure which volume name your USB key has, this command will show you what the possibilities are:
    ls /Volumes
    Please let me know if you have any trouble with these commands.

  • Why does Satellite Pro A300 not start when the power button is pressed?

    Suddenly my new Satellite Pro A300 will not start correctly when the power button is pressed. The situation is this: When I press the power button the Toshiba opening picture (Leading Innovation) appears and disappers quickly. Then there is a black screen for about 30 seconds. Then there is a rectangular frame with the text Microsoft Corporation underneath. And nothing happens however long I wait.
    In order to get on with the starting proces I then shut down the computer by pressing down the power button until the computer stops. ("The hard way to shut down")
    Now I press the power button shortly to turn on the computer. Then the computer starts normally with the Toshiba opening picture and after a few seconds I am asked to open the computer in safe mode or in normal mode. I now choose to open in normal mode and the computer opens normally and is ready to work.
    What shall I do to get a normal start procedure?

    When notebook starts normally (after choosing normal mode) shut down your notebook properly using START > Shut down option. Next start should be normal.
    When the OS is switched down on irregular way you will be always asked how to start it again (safe or normal mode).
    The same happen on my Satellite A300.

  • My Wireless mac keypad has stopped properly working. The keys sometime do not correspond to the result, or a a simultaneous duel actio, for example when the delete button is pressed the. Ursor does go backwards, but it also turns the sound up. Any ideas?

    My Wireless mac keypad has stopped properly working. The keys sometime do not correspond to the result, or a a simultaneous duel actio, for example when the delete button is pressed the. Ursor does go backwards, but it also turns the sound up. The keyboard is properly connected to the computer, and the battery life is up in the nineties.
    Help please !!!!

    Hi, thankyou for your response. Can I just confirm that you mean turning the computer on and off again, or re-booting the whole system. If it is the first I have already turned the system on and off, with no luck.
    Regards

  • Newsstand suppresses the home screen from the app switcher view when the home button is pressed?

    Newsstand suppresses the home screen from the app switcher view when the home button is pressed.
    Has anyone else seen this before, I needed to lock and unlock iPad to get back to the home screen.

    Aloha Ethan. Fortunately it's working as designed, but you'd never believe how many people wanted to argue with me smply because it worked differently. Can't please everybody I guess.  Bob. 

  • Vocal backing track stop playing when the cycle button is pressed.

    I am running the vocal backing track in Mainstage2.  I have various markers throughout the backing track, however, when I press the cycle button, the backing track stop playing and reverts to the start of the track.  Anyone know why this is happening?   

    Hello,
    Will try to explain how I understand the way a Question slide works:
    on the timeline you see a pausing point, this will be used twice
    when the user clicks on the Submit button, playhead is not released but the Success/Failure captions pop up, but you cannot control anything else such like stopping the audio
    when the user presses Y or clicks on the slide, the playhead is released, the Success/Failure actions are executed and (eventually - unless you changed navigation by those actions) the user is navigated to the next slide
    First thing you can change is the pausing point of the question slide, but once an audio clip started playing, this will continue and thus not solve your problem.
    It is only in that second step that you can do more customising by changing the Success/Failure actions, perhaps to an advanced action.
    Are you using this default behavior? And the audio is attached to what: to the slide or to the text captions for the questions and to the Success/Failure captions for the answers?
    I think the solution will be to skip the first step, by deleting the Success/Failure captions. When clicking on the Submit button in that situation, the Success/Failure actions will be executed immediately (and the playhead will be released). Attach the audio for the questions to an invisible object (rectangle without fill or stroke), that you hide with the advanced actions to be triggered by Success/Failure and show custom Text Captions for Success/Failure with audio attached to them. Because the playhead is now released, you will either have to time correctly so that the user will have to listen to the audio totally or to insert a static button widget that pauses the slide. But here I'm a bit stuck because I do not know which version of CP you are using, please?
    I blogged about using audio objects a while ago, but did not offer detailed explanations because no one asked for it until now. Have a look:
    Playtime with audio and widgets
    Lilybiri

  • A long left click shows the right click menu

    When I hold down the left mouse button, the right click menu appears.
    I want to turn off this function, but can't remember which extension controls it or whether the function is built in to Firefox.

    Hooray!! Found it! Thank you Google.
    I found an old - very old - thread on Mozillazine.org:
    http://forums.mozillazine.org/viewtopic.php?f=38&t=340572
    And it IS a normal Firefox feature, but is normally OFF.
    I think I must have recently turned it on after reading a "Firefox Tips and Tricks" article somewhere.
    Anyway, the preference is called "ui.click_hold_context_menus".
    And I just remembered that I added it in my "user.js" preferences file, amongst a load of others:
    * Disable the Delay When Installing New Extensions
    user_pref("security.dialog_enable_delay", 0);
    * To turn off the URL greying
    user_pref("browser.urlbar.formatting.enabled", false);
    * To unhide the "http" portion of a URL
    user_pref("browser.urlbar.trimURLs", false);
    * Enable spell checker in multi-line text boxes & single-line text boxes
    user_pref("layout.spellcheckDefault", 2);
    * Double underline style
    user_pref("ui.SpellCheckerUnderlineStyle", 4);
    * Cycle through open tabs with Ctrl+Tab
    user_pref("browser.ctrlTab.previews", false);
    * Disable Animations for Full Screen
    user_pref("browser.fullscreen.animateUp", 0);
    * Click and hold on a hyperlink to show the context menu
    user_pref("ui.click_hold_context_menus", true);
    * Instant Apply Preferences Without Closing Options Window
    user_pref("browser.preferences.instantApply", true);
    * Middle-click in any textfield, addressbar or searchbox to paste clipboard
    user_pref("middlemouse.paste", true);
    So there's a lesson to be learned here: don't add too many tweaks to your Firefox preferences at the same time or you may forget what you did!
    Thanks, all. I'll now mark this as "Solved"!

  • Mouse will only click with the right button...

    recently my macbook has decided that i dont need a right mouse button, and the touchpad is not responsive when clicking either. i have some suspicion that the trackpad button might be stuck. im also curious as to whether the usb's might be messed up. has anyone ever had this issue? how should i go about fixing it?

    nope, but i noticed since the lion update that the problem only persists if i touch the trackpad before i finish signing into my account...

  • How to perform action when the close button is pressed?

    i am using a JInternalFrame and i would like to perform some actions before the internal frame closes when i press the close button on the top right corner of the frame.
    i know the first step is:
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    what next? what actionlistener shd i use??
    thx very much

    Your first step is wrong.
    yourInternalFrame.addInternalFrameListener(
         new InternalFrameAdapter(){
      public void internalFrameClosing(InternalFrameEvent e){
        // do part
    });

  • Web DynPro Behaviour when the Reload button is pressed

    Hi,
    I'd like to know what is the behaviour of the Web DynPro when an user presses the Reload button on the browser.
    I'm asking this because I designed a WDP that has a view with some input fields, two button and a table to show the result of a search operation based on the content of the input fields.
    Some of the input fields are text inputs and others are dropdown list controls. In some cases, e.g. after having performed a search, if I hit the Reload button the content of one dropdown list was shown in another dropdown list.
    The dropdown lists and the other input fields are bound to some context attributes and nodes.
    I'm trying to figure out why the WDP is kept in this 'dirty state' when the page is reloaded.
    Thanks,
    Pietro.

    Hi Pietro,
    a reload of the Browser causes every time a reload of WDJ-Application. That means the content in the wdDoInit-Method is executed and the UI-Input elements are in initial state.
    If you want to store the selection in the Input fields and droodowns the only way is to store that in the session.
    Here is an example to do that.
    WDScopeUtil.put(WDScopeType.CLIENTSESSION_SCOPE, "ABC", "someValue");
    Than you have to read this in the init-Methods.
    WDScopeUtil.get(WDScopeType.CLIENTSESSION_SCOPE, "ABC");
    Regards
    Gunter

  • Can a today's date be added in a date field when the submit button is pressed?

    I created a form with a submit button and the form is sent via email.  Can the date when the form is submitted show up in a date field with the button is pressed?
    Any help with this is much appreciated. Thanks.

    Hi,
    there is a preSubmit event for form objects you can use.
    Select your date field, open the script editor and add this script (language is FormCalc) into the preSubmit event.
    $ = num2date(date(), "MM/DD/YYYY")

  • HT201401 My iphone4s struggles to open when the home button is pressed,seems blurd and grainy

    When pressing the home button on my iPhone 4S it has started to struggle and appear grainy and slow, tho it works well after that.

    Hi Ashyrah,
    Have you tried rebooting the phone? Hold down the Home and Power buttons at the same time and continue to hold them until the Silver Apple appears (no data will be lost, but it may take up to 20 seconds to reboot and display the Apple, so be patient).
    Once the Home screen comes up again, see if things are working a little more like you'd expect them to....
    Cheers,
    GB

  • My ipad screen will not come on, it gets a little brighter when the home button is pressed but nothing else happens. Is it faulty?

    Hi
    When I press the home button on my iPad the screen gets a little brighter but doesn't come on and none of the icons are visible.I also do not get the red swipe strip. Is my iPad screen faulty?

    Frozen or unresponsive iPad
    Resolve these most common issues:
        •    Display remains black or blank
        •    Touch screen not responding
        •    Application unexpectedly closes or freezes
    http://www.apple.com/support/ipad/assistant/ipad/
    iPad Frozen, not responding, how to fix
    http://appletoolbox.com/2012/07/ipad-frozen-not-responding-how-to-fix/
    iPad Frozen? How to Force Quit an App, Reset or Restart Your iPad
    http://ipadacademy.com/2010/11/ipad-frozen-how-to-force-quit-an-app-reset-or-res tart-your-ipad
    Black or Blank Screen on iPad or iPhone
    http://appletoolbox.com/2012/10/black-or-blank-screen-on-ipad-or-iphone/
    What to Do When Your iPad Won't Turn On
    http://ipad.about.com/od/iPad_Troubleshooting/ss/What-To-Do-When-Your-Ipad-Wo-No t-Turn-On.htm
    iOS: Not responding or does not turn on
    http://support.apple.com/kb/TS3281
    Home button not working or unresponsive, fix
    http://appletoolbox.com/2013/04/home-button-not-working-or-unresponsive-fix/
    Fixing an iPad Home Button
    http://tinyurl.com/om6rd6u
    iPad: Basic troubleshooting
    http://support.apple.com/kb/TS3274
     Cheers, Tom

Maybe you are looking for

  • Identification of Open Purchase Order...

    Hi, How can u identify Open purchase oder using the datasource 2LIS_02_ITM? Please throw a light on this... Thanks in Advance, Kishore

  • Apps bought on Iphone no longer sync to iTunes on PC

    The subject explains it all, my iPhone no longer syncs any of the apps purchased on the iPhone back onto iTunes on the PC. In fact, the itunes doesnt see any apps when connected to my iPhone - and I can't move or edit the apps contained on my iphone

  • OpenMQ embedded broker in Maven JUnit

    I have standalone application wich interacts with OpenMQ through JMS. Maven build tool is used. I want to write JUnit tests checking application interaction with OpenMQ. For this purpose I want to use OpenMQ embedded broker. I found https://mq.dev.ja

  • Request for DataSource from Souce System has a lesser SID than the request

    Hi Experts, Request REQU_48Q572FT5LVYNE8BD4KOD5WTV(72.714) has not or not correctly been updated; Please edit Message no. RSM096 Diagnosis Request REQU_48Q572FT5LVYNE8BD4KOD5WTV (72.714) for DataSource 2LIS_13_VDKON from source system EP1CLNT410 has

  • Best Config for 2 iTunes Libs, AppleTV, Wired and Wireless

    Hi there, Looking for a little configuration advice. AppleTV connected wired to AirportExtreme. PC 1 with iTunes (wife and kids library) connected wired to AirportExtreme. This is the "main" AppleTV library. PC 2 with iTunes (my library) connected wi