Is it possible to enable the selection of text from a JLabel? If not, what's the best alternative control to use, and how can it be configured to appear like a JLabel?
Yes you can do it :D.
JLabel is a class of java Swing . JLabel is used to display a short string or an image icon. JLabel can display text, image or both . JLabel is only a display of text or image and it cannot get focus .
A JTextField doesn't allow html-formatted text like a JLabel. If you want selectable html text you could alternatively try a JTextPane set to html formatting:
JTextPane f = new JTextPane(); f.setContentType("text/html"); // let the text pane know this is what you want f.setText("<html>Hello World</html>"); // showing off f.setEditable(false); // as before f.setBackground(null); // this is the same as a JLabel f.setBorder(null); // remove the border
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With