How to show tooltip on mouse right click...

Hi everyone!
I'm trying to show a tooltip when the user clicks on a button with the mouse right button but I'm having some problems starting, for example, with the tooltip position. For example, look at the the following example(without mouse listener yet):
public class test extends JFrame{
     private JToolTip      jtp      = new JToolTip();
     private JButton      button      = new JButton("a button");
     private JPanel           panel      = new JPanel();
     public test(){
          add(panel);
          panel.add(button);
          jtp.setTipText("a tooltip");
          jtp.setBounds(10,10,10,10);
          jtp.setVisible(true);
          panel.add(jtp);
     public static void main(String[] args) {
          test x = new test();          
        x.setVisible(true);
}Why the setBounds doesn't set the position? In fact it doesn't do anything.
Is it possible to the tooltip to partially overlap the button. As far I checked they only stay side by side.
I hope you understand my english...
Filipe

Use this code to show custom tool tip.
You should also handle the hiding of the tool tip.
JButton button = new JButton("test");
button.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
        if (e.getButton() == MouseEvent.BUTTON3) {
            JButton button = (JButton) e.getSource();
            JToolTip tooltip = button.createToolTip();
            PopupFactory popupFactory = PopupFactory.getSharedInstance();
            tooltip.setTipText("a tooltip");
            final Popup tooltip1 = popupFactory.getPopup(button, tooltip,
                    button.getLocationOnScreen().x + e.getX(),
                    button.getLocationOnScreen().y + e.getY() + 20);
            tooltip1.show();                       
});

Similar Messages

  • 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
    }

  • 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.

  • 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();
    }

  • 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.

  • CommandLink on mouse right click!!!

    Hi all,
    I have a problem in CommandLink,when i use mouse right click open in new tab or open in new window over the CommandLink it shows a previous page instead of actual page.I tried to overcome this using <redirect/> tag in faces-config xml but its a vain eventually.
    No request is generated to server while trying open in new tab.
    Any of u ever had this issue,any suggestions???.
    Awaiting reply.
    Thanks in advance,
    sundar.

    sundar82 wrote:
    Hi all,
    I have a problem in CommandLink,when i use mouse right click open in new tab or open in new window over the CommandLink it shows a previous page instead of actual page.I tried to overcome this using <redirect/> tag in faces-config xml but its a vain eventually.
    No request is generated to server while trying open in new tab.Which browser are you using?

  • Thunderbird Crashes on selection +"ctrl+c" or mouse right click

    Whenever I attempt to copy text from within a mail message, by selecting text & pressing ctrl+C TB crashes,
    or Just on Mouse Right Click TB Crashes

    So, I finally did a fresh install of OSX on iMac, and the right click came back.
    I think there was something corrupted on the system that somehow showed up after Adobe CS2. I reinstalled CS2 but up to now, no problems at all.
    Thanks all for the insights, they all helped a lot!

  • 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

    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

  • 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.

  • 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

  • Why keyboard and mouse right click not working in Solaris and Linux?

    Hi all,
    I have two problems:
    1) I am working on AWT/Swing application and its working fine in window enviornment,but while running on solaris and linux mouse right-click option window not poping up.
    2) Ctrl+c,Ctrl+v,Home and End keyboard key are not working in solaris and linux OS for same application.
    Pls provide me some solution for these problem.
    -Dinesh

    Hi Nik,
    Thanks for reply. I found some solution for the above problem.
    For mouse right click there was problem in my source code.I have not implemented the mousePressed() method
    In case of keyboard Home, End and arrow key working fine after exporting AWTUSE_TYPE4_PATCH=false; in solaris and linux
    But still Ctrl-c and Ctrl-v not working.
    I am using JDK1.5.0_07+Eclipse IDE 3.1
    -Dinesh

  • How can I remove the default right click option of the text Area control?

    How can I remove the default right click option of the text Area control?
    Is there any way to disable this control in any of the text controls available?

    The iPhone does not store email addresses for received mail. The iPhone stores all email addressees for sent mail in a list of previous recipients. The list of previous recipients is not synced with Outlook or any address book, but the list of previous recipients is included with the iPhone's backup which is updated by iTunes as the first step during the iTunes sync process. The auto-addrss feature pulls from your contacts on the iPhone and from the list of previous recipients.
    Different from the Mail.app on a Mac, there is no access to the list of previous recipients on the iPhone to remove a previous recipient from the list, or to add a previous recipient to contacts that is not already entered - not at the present time anyway.
    The only way to purge the existing list at the present time is by restoring your iPhone with iTunes as a new iPhone or not from your iPhone's backup.
    Hopefully access to the list of previous recipients will be included with the iOS 5 update.

Maybe you are looking for

  • My Macbook Pro keeps freezing and crashing!

    Hello, I've had my MBP for a year and seven months (as of April 2014). At the beginnings of March 2014, it began freezing, showing these flickering horizontal lines and squares, and then, I had to do a hard boot to get it to work again. Back in March

  • User exit in sales order

    Hi All, I want to know if there is a way (user exit) that could look at the Sales Order Type , particular Item Pricing Condition  and Ship-to party State and set the materialu2019s tax classification (VBAP/TAXM1) to u201C0u201D (Exempt) ? Thanks in A

  • Build in a crucial M500 SSD into a Mac Book Pro 2013 - now it crashes

    Hi guys, first of all greetings from Germany, I hope you can understand my horrible english Today I bought a Macbook Pro together with a Crucial M500 SSD harddisk. With the standard HD the Macbook runs perfect. But when I start it with the new SSD th

  • Not Booting From DVD Macbook Pro Early 2011

    Put a brand new Snow Leopard disc in the drive. Started the laptop with ALT depressed and when the available drives came up I selected DVD Drive. Disk is spinning, but apple logo screen just sits there and 3 beeps keep repeating. Does nothing. Anyone

  • USB thumb drive mounting buggy ...

    Mounting a usb stick has become buggy. How do I begin with troubleshooting this? $ sudo lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 1 7.3G 0 disk └─sdb1 8:17 1 7.3G 0 part sr0 11:0 1 1024M 0 rom $ sudo mount /dev/sdb1 /mnt/usb $ ls /mnt/us