Pages

Set JCheckBox text font

Source code below will show you, how to set JCheckBox text font.

**************************************************************************
COMPLETE SOURCE CODE FOR : SetJCheckBoxTextFont.java
**************************************************************************


import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.SwingConstants;

import java.awt.BorderLayout;
import java.awt.Font;

public class SetJCheckBoxTextFont
{
public static void main(String[]args)
{
//Create check box using JCheckBox with text ( I am a check box )
JCheckBox checkBox=new JCheckBox("I am a check box");

//Create font.
//Font Name : Tahoma
//Font Style : Default check box font style
//Font Size : Default check box font size
Font newCheckBoxFont=new Font("Tahoma",checkBox.getFont().getStyle(),checkBox.getFont().getSize());

//Set JCheckBox font using new created font
checkBox.setFont(newCheckBoxFont);

//Create a window using JFrame with title ( Set JCheckBox text font )
JFrame frame=new JFrame("Set JCheckBox text font");

//Set JFrame layout to BorderLayout
frame.setLayout(new BorderLayout());

//Add created check box into JFrame
frame.add(checkBox);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size
frame.setSize(400,200);

//Make JFrame visible
frame.setVisible(true);
}
}


**************************************************************************
JUST COMPILE AND EXECUTE IT
**************************************************************************
Related Posts Plugin for WordPress, Blogger...