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

Categories

0 votes
608 views
in Technique[技术] by (71.8m points)

swing - How do I write superscript word for checkbox text in java?

I made few checkboxes using swing in Java. I want to write a superscript text for the checkboxes but I'm not sure how.

The code currently looks like this.

JCheckBox hCheckBox = new JCheckBox("[M + H]+");

I want to have "+" sign inside the JCheckBox parameter superscripted. What's an easy way to do this?

Thank you in advance.

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Java buttons support html in their text. You need to format the string a little differently though. Try this:

JCheckBox hCheckBox = new JCheckBox("<html>[M + H]<sup>+</sup></html>"); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...