3

I have the user enter some words through a JTextField. I want to set the font of the string. Here is what I have so far.

Font f;
f = new Font(input.getText(), Font.ITALIC, 32);
word = new JLabel(f, SwingConstants.CENTER);

Unfortunately, Java is throwing me a compiler error because JLabel doesn't accept Font as a parameter. Is it possible to set the font of a string retrieved from a text field and have it displayed on a JFrame?

Andrew Thompson
  • 166,747
  • 40
  • 210
  • 420
carebear
  • 721
  • 1
  • 7
  • 16

1 Answers1

4

See JComponent.setFont(Font).

Sets the font for this component.


But better than a text field to set a font name, see this answer for a (styled) combo or this answer that uses a list:

Community
  • 1
  • 1
Andrew Thompson
  • 166,747
  • 40
  • 210
  • 420