Hello there,
I am using the JTextPane in my Java Swing Application. How do I make it Handle Hypelinks. Like lets say the use enters
\\some_foldername\some_subfolder_foldername\some_file.xls or any other file type, It should Automatically, treat it as a hyperlink.
Is it Possible to have such a functionlaity
JTextPane Hyperlink Functionality
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
public class TextSamplerDemo extends JPanel {
public TextSamplerDemo() {
setLayout(new BorderLayout());
// Create a text pane.
JTextPane textPane = new JTextPane();
setPreferredSize(new Dimension(250, 155));
setMinimumSize(new Dimension(10, 10));
// Put everything together.
add(textPane, BorderLayout.LINE_START);
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("Hyperlinks in Java Editors");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new TextSamplerDemo());
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
UIManager.put("swing.boldMetal", Boolean.FALSE);
createAndShowGUI();
}
});
}
}