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

Set JButton text font

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

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


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

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

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

//Create font.
//Font Name : Tahoma
//Font Style : Default button font style
//Font Size : Default button font size
Font newButtonFont=new Font("Tahoma",button.getFont().getStyle(),button.getFont().getSize());

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

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

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

Get JRadioButton text

Source code below will show you how to get text from JRadioButton.

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


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;

import java.awt.BorderLayout;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class GetJRadioButtonText implements ActionListener
{
//Create button with text ( Click me to get JRadioButton text )
JButton button=new JButton("Click me to get JRadioButton text");

//Create JRadioButton with text ( I am a radio button )
JRadioButton radioButton=new JRadioButton("I am a radio button");

//Create a window with title ( Get JRadioButton text )
JFrame frame=new JFrame("Get JRadioButton text");

public GetJRadioButtonText()
{
//Add action listener to button
button.addActionListener(this);

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

//Add created radio button into JFrame
frame.add(radioButton,BorderLayout.CENTER);

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

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

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

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

public void actionPerformed(ActionEvent event)
{
if(event.getSource()==button)
{
//Method getText will get text from radio button
JOptionPane.showMessageDialog(frame,"JRadioButton text is : "+radioButton.getText());
}
}

public static void main(String[]args)
{
GetJRadioButtonText gjbt=new GetJRadioButtonText();
}
}


***********************************************************************
JUST COMPILE AND EXECUTE IT
***********************************************************************

Get JCheckBox text

Source code below will show you how to get text from JCheckBox.

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


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JCheckBox;

import java.awt.BorderLayout;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class GetJCheckBoxText implements ActionListener
{
//Create button with text ( Click me to get JCheckBox text )
JButton button=new JButton("Click me to get JCheckBox text");

//Create JCheckBox with text ( I am a checkbox )
JCheckBox checkBox=new JCheckBox("I am a checkbox");

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

public GetJCheckBoxText()
{
//Add action listener to button
button.addActionListener(this);

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

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

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

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

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

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

public void actionPerformed(ActionEvent event)
{
if(event.getSource()==button)
{
//Method getText will get text from check box
JOptionPane.showMessageDialog(frame,"JCheckBox text is : "+checkBox.getText());
}
}

public static void main(String[]args)
{
GetJCheckBoxText gjbt=new GetJCheckBoxText();
}
}


***************************************************************
JUST COMPILE AND EXECUTE IT
***************************************************************

Get JLabel text

Source code below will show you how to get text from JLabel.

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


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JLabel;

import java.awt.BorderLayout;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class GetJLabelText implements ActionListener
{
//Create button with text ( Click me to get JLabel text )
JButton button=new JButton("Click me to get JLabel text");

//Create JLabel with text ( I LOVE YOU )
JLabel label=new JLabel("I LOVE YOU");

//Create a window with title ( Get JLabel text )
JFrame frame=new JFrame("Get JLabel text");

public GetJLabelText()
{
//Add action listener to button
button.addActionListener(this);

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

//Add created label into JFrame
frame.add(label,BorderLayout.CENTER);

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

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

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

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

public void actionPerformed(ActionEvent event)
{
if(event.getSource()==button)
{
//Method getText will get text from label
JOptionPane.showMessageDialog(frame,"JLabel text is : "+label.getText());
}
}

public static void main(String[]args)
{
GetJLabelText gjbt=new GetJLabelText();
}
}


*****************************************************************
JUST COMPILE AND EXECUTE IT
*****************************************************************

Get JTextArea text

Source code below will show you how to get text from JTextArea.

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


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;

import java.awt.BorderLayout;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class GetJTextAreaText implements ActionListener
{
//Create button with text ( Click me to get JTextArea contents )
JButton button=new JButton("Click me to get JTextArea contents");

//Create JTextArea
JTextArea textArea=new JTextArea();

//Create a window with title ( Get JTextArea text )
JFrame frame=new JFrame("Get JTextArea text");

public GetJTextAreaText()
{
//Set line wrapping for text area to true
textArea.setLineWrap(true);

//Add action listener to button
button.addActionListener(this);

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

//Add created text area into JFrame
frame.add(textArea,BorderLayout.CENTER);

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

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

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

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

public void actionPerformed(ActionEvent event)
{
if(event.getSource()==button)
{
//Method getText will get text from text area
JOptionPane.showMessageDialog(frame,"JTextArea text is : "+textArea.getText());
}
}

public static void main(String[]args)
{
GetJTextAreaText gjbt=new GetJTextAreaText();
}
}


**************************************************************************
JUST COMPILE AND EXECUTE IT
**************************************************************************

Get JTextField text

Source code below will show you how to get text from JTextField.

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


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import java.awt.GridLayout;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class GetJTextFieldText implements ActionListener
{
//Create button with text ( Click me to get JTextField contents )
JButton button=new JButton("Click me to get JTextField contents");

//Create JTextField
JTextField textField=new JTextField(10);

//Create a window with title ( Get JTextField text )
JFrame frame=new JFrame("Get JTextField text");

public GetJTextFieldText()
{
//Add action listener to button
button.addActionListener(this);

//Set JFrame layout to GridLayout
frame.setLayout(new GridLayout(2,1));

//Add created text field into JFrame
frame.add(textField);

//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);
}

public void actionPerformed(ActionEvent event)
{
if(event.getSource()==button)
{
//Method getText will get text from text field
JOptionPane.showMessageDialog(frame,"JTextField text is : "+textField.getText());
}
}

public static void main(String[]args)
{
GetJTextFieldText gjbt=new GetJTextFieldText();
}
}


**********************************************************************
JUST COMPILE AND EXECUTE IT
**********************************************************************

Get JButton text

Source code below will show you how to get text from JButton.

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


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

import java.awt.FlowLayout;

public class GetJButtonText
{
public static void main(String[]args)
{
//Create a button with text ( Click me )
JButton button=new JButton("Click me");

JFrame frame=new JFrame("Get JButton text");
frame.setLayout(new FlowLayout());
frame.add(button);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,300);
frame.setVisible(true);

//Method getText() will get text from JButton
JOptionPane.showMessageDialog(frame,"JButton text is : "+button.getText());
}
}


************************************************************************
JUST COMPILE AND EXECUTE IT
************************************************************************

JSlider label

Source code below will show you, how to set major and minor tick for a JSlider and make the label visible on JSlider.

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


import javax.swing.JSlider;
import javax.swing.JFrame;

import java.awt.FlowLayout;

public class JSliderLabel
{
public static void main(String[]args)
{
//Create a slider using JSlider
//Maximum value = 100
//Minimum value = 0
//Initial value = 50
JSlider slider=new JSlider();

//Set minor tick spacing to 1
slider.setMinorTickSpacing(1);

//Set major tick spacing to 10
slider.setMajorTickSpacing(10);

//Enable label on JSlider
slider.setPaintLabels(true);

//Create a window using JFrame with title ( JSlider label )
JFrame frame=new JFrame("JSlider label");

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

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

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

//Set JFrame size to :
//WIDTH : 400 pixels
//HEIGHT : 200 pixels
frame.setSize(400,200);

//Make JFrame visible. So, we can see it.
frame.setVisible(true);
}
}


**************************************************************************
JUST COMPILE AND EXECUTE IT
**************************************************************************

JSlider tick

Source code below will show you, how to set major and minor tick for a JSlider and make the tick visible on JSlider.

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


import javax.swing.JSlider;
import javax.swing.JFrame;

import java.awt.FlowLayout;

public class JSliderTick
{
public static void main(String[]args)
{
//Create a slider using JSlider
//Maximum value = 100
//Minimum value = 0
//Initial value = 50
JSlider slider=new JSlider();

//Set minor tick spacing to 1
slider.setMinorTickSpacing(1);

//Set major tick spacing to 10
slider.setMajorTickSpacing(10);

//Enable tick on JSlider
slider.setPaintTicks(true);

//Create a window using JFrame with title ( JSlider tick )
JFrame frame=new JFrame("JSlider tick");

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

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

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

//Set JFrame size to :
//WIDTH : 400 pixels
//HEIGHT : 200 pixels
frame.setSize(400,200);

//Make JFrame visible. So, we can see it.
frame.setVisible(true);
}
}


************************************************************************
JUST COMPILE AND EXECUTE IT
************************************************************************

Create slider using JSlider

Source code below will show you, how to create slider in java using JSlider class.

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


import javax.swing.JSlider;
import javax.swing.JFrame;

import java.awt.FlowLayout;

public class CreateSliderUsingJSlider
{
public static void main(String[]args)
{
//Create a slider using JSlider
JSlider slider=new JSlider();

//Create a window using JFrame with title ( Create slider using JSlider )
JFrame frame=new JFrame("Create slider using JSlider");

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

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

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

//Set JFrame size to :
//WIDTH : 400 pixels
//HEIGHT : 200 pixels
frame.setSize(400,200);

//Make JFrame visible. So, we can see it.
frame.setVisible(true);
}
}


******************************************************************
JUST COMPILE AND EXECUTE IT
******************************************************************

Create slider in java

In java, you can create slider using JSlider class.

RELAXING NATURE VIDEO