Below Java code example shows how to change the font for JTextField swing class component. Syntax Font f=new Font("Tahoma",F...
Below Java code example shows how to change the font for JTextField swing class component.
Syntax
Font f=new Font("Tahoma",Font.ITALIC,18);
field.setFont(f);
Java JTextField setFont Code
/**
*
* @author Eric
* Blog:www.techoverload.net
*This Example shows how to set JTextField Font
*/
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JTextField;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
public class JTextFieldExample extends JFrame{
public JTextField field;
JTextFieldExample()
{
super("JTextField methods");
setLayout(new FlowLayout());
//create JTextField object
field=new JTextField("Font JTextField Example");
Font f=new Font("Tahoma",Font.ITALIC,18);
field.setFont(f);
add(field);
setSize(new Dimension(300,300));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String args[])
{
new JTextFieldExample();
}
}