Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
256 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...