Pages

Set JButton text bold and italic

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

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


import javax.swing.JButton;
import javax.swing.JFrame;

import java.awt.FlowLayout;
import java.awt.Font;

public class SetJButtonTextBoldAndItalic
{
public static void main(String[]args)
{
//Create button with text ( MY BUTTON )
JButton button=new JButton("MY BUTTON");

//Create font.
//Font Name : Default button font
//Font Style : Bold And Italic
//Font Size : Default button font size
Font newButtonFont=new Font(button.getFont().getName(),Font.ITALIC+Font.BOLD,button.getFont().getSize());

//Set JButton font using new created font
button.setFont(newButtonFont);

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

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

//Add created button into JFrame
frame.add(button);

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

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

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


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