Create password field in java

In java, you can create a password field using JPasswordField class.

Create list using JList

Source code below will show you, how to create list in java using JList.

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


import javax.swing.JList;
import javax.swing.JFrame;

import java.awt.FlowLayout;

public class CreateListUsingJList
{
public static void main(String[]args)
{
//Create contents for JList using array
//Using String as array type
String[]listContents={"HI","HA","HU"};

//Create a list using JList
JList list=new JList(listContents);

//Create a JFrame that will be use to put JList into it
JFrame frame=new JFrame("Create list using JList");

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

//add created JList into JFrame
frame.add(list);

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

//set JFrame size
frame.setSize(400,400);

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


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

Create list in java

In java, you can create list using JList class.

Create combo box using JComboBox

Source code below will show you, how to create a combo box in java using JComboBox class.

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


import javax.swing.JComboBox;
import javax.swing.JFrame;

import java.awt.FlowLayout;

public class CreateComboBoxUsingJComboBox
{
public static void main(String[]args)
{
//Create contents for JComboBox using array
//Using String as array type
String[]comboBoxContents={"HI","HA","HU"};

//Create a combo box using JComboBox
JComboBox comboBox=new JComboBox(comboBoxContents);

//Create a JFrame that will be use to put JComboBox into it
JFrame frame=new JFrame("Create combo box using JComboBox");

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

//add created JComboBox into JFrame
frame.add(comboBox);

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

//set JFrame size
frame.setSize(400,400);

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


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

Create combo box in java

In java, you can create combo box using JComboBox class.

Create radio button using JRadioButton

Source code below will show you, how to create a radio button in java with text HI using JRadioButton.

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


import javax.swing.JRadioButton;
import javax.swing.JFrame;

public class CreateRadioButtonUsingJRadioButton
{
public static void main(String[]args)
{
//Create radio button with text HI
JRadioButton radioButton=new JRadioButton("HI");

//Create JFrame to place created JRadioButton
JFrame frame=new JFrame("Create radio button using JRadioButton");

//add created radio button into JFrame
frame.add(radioButton);

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

//set JFrame size
frame.setSize(450,65);

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


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

Create radio button in java

In java, you can create radio button using JRadioButton class.

Create check box using JCheckBox

Source code below will show you, how to create a check box in java with text HI using JCheckBox.

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


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

public class CreateCheckBoxUsingJCheckBox
{
public static void main(String[]args)
{
//Create check box with text HI
JCheckBox checkBox=new JCheckBox("HI");

//Create JFrame to place created JCheckBox
JFrame frame=new JFrame("Create check box using JCheckBox");

//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(450,65);

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


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

Create check box in java

In java, you can create check box using JCheckBox class.

Create label using JLabel

Source code below will show you, how to create label in java using JLabel. We will use JLabel when we want to add text or image into graphical user interface.

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


import javax.swing.JLabel;
import javax.swing.JFrame;

public class CreateLabelUsingJLabel
{
public static void main(String[]args)
{
//Create a label with text My First Label using JLabel
JLabel label=new JLabel("My First Label");

//Create a JFrame that we will use to place JLabel
JFrame frame=new JFrame("Create label using JLabel");

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

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

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

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


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