import java.awt.Font; import javax.swing.JTextField; JTextField textField = new JTextField(); Font font = new Font("Arial", Font.PLAIN, 12); textField.setFont(font);
import java.awt.Font; import javax.swing.JTextField; JTextField textField = new JTextField(); Font defaultFont = textField.getFont(); String fontName = getInputFromUser(); // user inputs font name int fontSize = Integer.parseInt(getInputFromUser()); // user inputs font size Font font = new Font(fontName, Font.PLAIN, fontSize); textField.setFont(font != null ? font : defaultFont); // set the font of the text fieldBoth of these examples use the javax.swing package library.