Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6114073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:55:55+00:00 2026-05-23T14:55:55+00:00

I want to add some tooltips to only a certain text inside a JTextPane.

  • 0

I want to add some tooltips to only a certain text inside a JTextPane. As an example, if there is a reference link text inside the JTextPane I want to add a tooltip to that text to show the link. Is there any way I can achieve this functionality?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:55:55+00:00Added an answer on May 23, 2026 at 2:55 pm

    Good question.

    First Swing supports HTML, so to show tooltip with link you just have to say:

    comp.setToolTipText("<html><a href='http://www.google.com'>google</a></html>");

    The problem is making this tooltip clickable.

    Unfortunately it is not done by Swing itself.

    Tooltip is created by ToolTipManager. When you call setToolTipText() Jcomponent adds the instance of itself to shared instance of Tooltip manager that is responsible on showing the tooltip (using method show() that cannot be overridden. You cannot change the tooltip manager itself too.

    So, the best solution I can suggest is to do the following.
    You can listen to the AWT events using Toolkit.getDefaultToolkit().addAWTEventListener()

    So, when tooltip is being showed catch it, discover, and add mouse listener on it. This mouse listener will make the tooltip itself clickable.

    Here is the exercise I have just written. You can use it as a reference. Good luck.

        public static void main(String[] args) throws InterruptedException, InvocationTargetException {
            final JFrame f = new JFrame("test");
            f.setSize(100, 100);
    
    
            JLabel l = new JLabel("<html><a href='http://www.google.com'>google</a></html>");
            l.setToolTipText("<html><a href='http://www.google.com'>google</a></html>");
    
    
            long mask = AWTEvent.COMPONENT_EVENT_MASK |
    //      AWTEvent.CONTAINER_EVENT_MASK |
    //      AWTEvent.FOCUS_EVENT_MASK |
    //      AWTEvent.KEY_EVENT_MASK |
    //      AWTEvent.MOUSE_EVENT_MASK |
    //      AWTEvent.MOUSE_MOTION_EVENT_MASK |
            AWTEvent.WINDOW_EVENT_MASK |
            AWTEvent.ACTION_EVENT_MASK |
            AWTEvent.ADJUSTMENT_EVENT_MASK |
            AWTEvent.ITEM_EVENT_MASK |
            AWTEvent.TEXT_EVENT_MASK;
    
            Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
                @Override
                public void eventDispatched(AWTEvent event) {
                    int id = event.getID();
                    Object source = event.getSource();
                    if (id == 101 && source instanceof JToolTip) {
                        JToolTip tooltip = (JToolTip)source;
    
                        //System.out.println("" + event.getID() + " " + event.getSource());
    
                    }
    
                }
            }, mask);
            f.add(l);
            f.setVisible(true);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add a tooltip to the DateTimePicker Calendar that show some informations
I want to add some functionality track certain calls to ActiveX object methods in
I want to add some classes to a CodeIgniter project that aren't models, views,
I have a view that I want to add some custom drawing to. I
I want to add some functionality to existing (closed-source) applications on Android. For example:
I have got a Listbox and i want to add some Items. There are
I want to add some tail marks to several strings. Are there any marks
i want to add some text fields and the buttons to the popover view
I want to add some HTML elements that have the same class name. So,
I want to add some text to a screen. Since this text changes color

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.