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

  • SEARCH
  • Home
  • 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 9106083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:15:17+00:00 2026-06-17T02:15:17+00:00

I apologize for the long question. I was browsing a forum the other day

  • 0

I apologize for the long question.

I was browsing a forum the other day and I saw a few pieces of text that were linking to youtube and other sites.
I had to always highlight and then copy and paste or right click “go to” in google chrome browser.

Since I’ve been playing with Java a little bit, I thought about making my own little program that will give a link to text that has an address . For example if I said “hey, check this video out I saw the other day ‘www.youtube.com’ ” I’d want the youtube part to be clickable.

Could anybody tell me if such a thing is possible and if it is, what libraries would I have to use for this and lastly, how can I find a list of all imports and libraries in java?

Thanks.

  • 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-06-17T02:15:18+00:00Added an answer on June 17, 2026 at 2:15 am

    Use HTML in JEditorPane and add HyperLinkListener to detect click on URLs.

    Than use Desktop API to open default browser with the URL.

    Something like:

    enter image description here

    import java.awt.Desktop;
    import javax.swing.JEditorPane;
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;
    import javax.swing.event.HyperlinkEvent;
    import javax.swing.event.HyperlinkListener;
    
    public class Test {
    
        public static void main(String[] argv) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
    
                    JEditorPane jep = new JEditorPane();
                    jep.setContentType("text/html");//set content as html
                    jep.setText("Welcome to <a href='http://stackoverflow.com/'>StackOverflow</a>.");
    
                    jep.setEditable(false);//so its not editable
                    jep.setOpaque(false);//so we dont see whit background
    
                    jep.addHyperlinkListener(new HyperlinkListener() {
                        @Override
                        public void hyperlinkUpdate(HyperlinkEvent hle) {
                            if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) {
                                System.out.println(hle.getURL());
                                Desktop desktop = Desktop.getDesktop();
                                try {
                                    desktop.browse(hle.getURL().toURI());
                                } catch (Exception ex) {
                                    ex.printStackTrace();
                                }
                            }
                        }
                    });
    
    
                    JFrame f = new JFrame("HyperlinkListener");
                    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    f.add(jep);
                    f.pack();
                    f.setVisible(true);
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Disclaimer: I apologize that this question is so long. I have added code as
I apologize in advance; this is a long question. I've tried to simplify as
I apologize upfront for the long question, with multiple subquestions, but the question is
This question is going to be rather long, so I apologize preemptively. In Python
This is a long question so i apologize if it takes a while to
First off, let me apologize in advance for the extremely long question -- kudos
I apologize in advance for the long-winded question. I'm having trouble with a self-signed
My (long, I apologize) question is a follow-on to: How to add tagging with
I apologize in advance for the long-winded question but I wanted to make sure
First of all, I want to apologize for such a long question. You don't

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.