Hyperlinks in JLabels

This is the code that I have in the Test2.java file in the test2 package in the Test2 project;

package test2;

import javax.swing.JFrame;

public class Test2 {
    public static void main(String[] args) {
    JFrame mainWindow = new HtmlWindow("<html>"
            + "<a href=\"http://stackoverflow.com\">"
            + "blah</a></html>");
        mainWindow.setVisible(true);
    }
}

In the same package, I have this code in the HtmlWindow.java file;

package test2;

import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JLabel;


class HtmlWindow extends JFrame {
    public HtmlWindow(String refreshGrid) {
        super("blah");
        setSize(300, 100);
        Container content = getContentPane();
        String labelText = refreshGrid;
        JLabel coloredLabel = new JLabel (labelText, JLabel.CENTER); 
        content.add(coloredLabel, BorderLayout.NORTH);

    }

}

When I start a project, I get a window with the word "blah" at the expected location, blue and underlined, but the cursor does not change when I hover over a word, and nothing happens when I click on it.

My questions are as follows:

  • Is it possible to place hyperlinks in jLabels?
  • If so, am I doing something wrong, or is the program not working correctly?
  • , ? , JButtons, , , , , JButtons , , "". , JEditorPane?
+5
2

Swing - . HTML, , . , , , . , LinkLabel, , , .

+4

, , -. , , ActionListener JLabel Desktop.getDesktop().browse(new URI("..."));.

, . , , , , , , , exec Process. , , .

, , ( , , , , , , ). , , JButton.

+3

All Articles