简体   繁体   中英

Set the font of texts retrieved from JTextField

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?

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM