YellowSoloCup
YellowSoloCup

Reputation: 101

Java Text Formatting bold

I am having a hard time understanding how to bold the text in my GUI program. The program shows the initial value of my calculator program to be 0.0 but I need to be able to make it bold and set it to 14 font. Is there any easy way to do this?

JPanel x = new JPanel(new BorderLayout());
         JTextField z = new JTextField();
         z.setEditable(false);
         z.setText("0.0");
         x.add(field, BorderLayout.NORTH);

Upvotes: 5

Views: 26323

Answers (2)

martinez314
martinez314

Reputation: 12332

Try this:

z.setFont(z.getFont().deriveFont(Font.BOLD, 14f));

deriveFont() has the advantage of being able to base your new font on the existing one. This will maintain the font characteristics that you don't mean to change.

Upvotes: 18

Salah
Salah

Reputation: 8657

You can simply change you JTextField font by doing the following:

f.setFont(new Font("Tahoma", Font.BOLD, 14));// Tahoma is an example, you could use any forn you want.

Upvotes: 0

Related Questions