Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Set JCheckBox text bold and italic (Java)

Source code below will show you, how to set JCheckBox text to bold and italic.

************************************************************************
COMPLETE SOURCE CODE FOR : SetJCheckBoxTextBoldAndItalic.java
************************************************************************
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.SwingConstants;

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

public class SetJCheckBoxTextBoldAndItalic
{
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 : Default check box font
 //Font Style : Bold And Italic
 //Font Size : Default check box font size
 Font newCheckBoxFont=new Font(checkBox.getFont().getName(),Font.ITALIC+Font.BOLD,checkBox.getFont().getSize());

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

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

 //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
************************************************************************