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 124123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:23:44+00:00 2026-05-11T04:23:44+00:00

What is the best way to add a hyperlink in a JLabel? I can

  • 0

What is the best way to add a hyperlink in a JLabel? I can get the view using html tags, but how to open the browser when the user clicks on it?

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T04:23:44+00:00Added an answer on May 11, 2026 at 4:23 am

    You can do this using a JLabel, but an alternative would be to style a JButton. That way, you don’t have to worry about accessibility and can just fire events using an ActionListener.

      public static void main(String[] args) throws URISyntaxException {     final URI uri = new URI('http://java.sun.com');     class OpenUrlAction implements ActionListener {       @Override public void actionPerformed(ActionEvent e) {         open(uri);       }     }     JFrame frame = new JFrame('Links');     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     frame.setSize(100, 400);     Container container = frame.getContentPane();     container.setLayout(new GridBagLayout());     JButton button = new JButton();     button.setText('<HTML>Click the <FONT color=\'#000099\'><U>link</U></FONT>'         + ' to go to the Java website.</HTML>');     button.setHorizontalAlignment(SwingConstants.LEFT);     button.setBorderPainted(false);     button.setOpaque(false);     button.setBackground(Color.WHITE);     button.setToolTipText(uri.toString());     button.addActionListener(new OpenUrlAction());     container.add(button);     frame.setVisible(true);   }    private static void open(URI uri) {     if (Desktop.isDesktopSupported()) {       try {         Desktop.getDesktop().browse(uri);       } catch (IOException e) { /* TODO: error handling */ }     } else { /* TODO: error handling */ }   } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whats the best way to add a user/group in linux using C++ is there
What is the best way to add an item to IEnumerable collection using Extension
What is the best way to add a background image to a JPanel/JLabel when
What is the best way to add a border to an html table when
What is the best way to add bullet-like images before text? I can set
What's the best way to add a loading page/splash page when a user first
Can anyone tell me the best way to add a viewcontroller with nib file
What is the best way to add text to the beginning of a file
What is the best way to add a sense of order in Doctrine Nested
What's the best way to add foreign keys to my existing tables in Rails

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.