Pages

Set JButton text size

Source code below will show you, how to set JButton text size.

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


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

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

public class SetJButtonTextSize
{
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 : Default button font style
//Font Size : 16
Font newButtonFont=new Font(button.getFont().getName(),button.getFont().getStyle(),16);

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

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

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