Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JButton text with different font family in different words

I am trying to achieve a button with its text having two different font family.

I think, it can be achieved using HTML, as said on this page. http://docs.oracle.com/javase/tutorial/uiswing/components/html.html

I've tried the following code, but it's not working.

JButton button = new JButton("<html>Hello <font family=Serif>World</font></html>");

May be the font tag attribute family is wrong!

like image 477
Akshat Avatar asked Jan 10 '14 13:01

Akshat


People also ask

Do buttons inherit font?

Buttons have their own font-family, so don't inherit from the cascade unless you tell it to.


1 Answers

May be the font tag attribute family is wrong!

It is indeed, the right tag should be:

<font face="Serif"></font>

Take a look to HTML font tag. So in your case:

JButton button = new JButton("<html>Hello <font face=\"Serif\">World</font></html>");

Picture

enter image description here

like image 78
dic19 Avatar answered Sep 20 '22 04:09

dic19