JTextField.setFont

Font : Determines the font to be used when drawing text. The font attribute is set by calling the setFont(Font font) method for the graphics context. The default font is the font set for the component.

Program

gfdgfdgfdg

 

 

 

Progarm Source

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.Font;
import java.awt.FlowLayout;

class Frame extends JFrame {
    
    Frame()
    {
        setTitle("JTextField with Font");
        setLayout(new FlowLayout());
        setJTextFields();
        setSize(700, 200);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    private void setJTextFields()
    {
        JLabel     fs = new JLabel("Font Styles");
        JTextField t1 = new JTextField("Hajsof",10);
        JTextField t2 = new JTextField("Hajsof",10);
        JTextField t3 = new JTextField("Hajsof",10);
        t1.setFont(new Font(Font.SERIF,Font.BOLD,12));
        t2.setFont(new Font(Font.DIALOG,Font.PLAIN,14));
        t3.setFont(new Font(Font.MONOSPACED,Font.ITALIC,16));
        add(fs);
        add(t1);
        add(t2);
        add(t3); 
    }
}

public class Javaapp {
   
    public static void main(String[] args) {
        
        Frame frame = new Frame();
    }
}

Leave a Comment