user2822187
user2822187

Reputation: 307

Apply small caps to a text in java swing

I have the following code:

  headerLabel.setText("TEST APPLICATION DATA");  

// headerLabel.setFont(new Font("",Font.ITALIC,25)); headerLabel.setFont(new Font("Century Schoolbook L",Font.BOLD,22));

THe font that is required is Century SchoolBook and I want the first letter of each word to be bigger in size than other letters of the word. All letters in capitals but first letter of each word should have bigger size than other letters .

How should I apply this?

Upvotes: 0

Views: 477

Answers (1)

camickr
camickr

Reputation: 324197

Read the section from the Swing tutorial on How to Use HTML in Swing Components.

So you wound need to wrap the text in HTML. The first letter would use a different font size than the remaining letters.

Edit:

Something like:

JLabel label2 = new JLabel("<html><font size=\"25\">T</font>EST APPLICATION DATA</html>");
label2.setFont(new Font("Century Schoolbook L" ,Font.BOLD ,22));

Edit 2:

Another option is to use a customized JTextPane (so that it looks like a JLabel. Then you can apply different Fonts to the text. The benefit of this approach is that when you don't need to parse the text to build the HTML String and when you use the getText() method you will get the text, not the formatted string.

Upvotes: 2

Related Questions