Pages

Add JToggleButton into JFrame

Source code below will show how to add JToggleButton into JFrame.

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


import javax.swing.JToggleButton;
import javax.swing.JFrame;

import java.awt.FlowLayout;

public class AddJToggleButtonIntoJFrame
{
public static void main(String[]args)
{
//Create a JToggleButton with text(Java)
JToggleButton toggleButton=new JToggleButton("Java");

//Create a JToggleButton with text(Java_2) and selection state
//If selection state true, JToggleButton will be pressed
JToggleButton toggleButton2=new JToggleButton("Java_2",true);

//Create a JFrame with title(Add toggle button)
JFrame frame=new JFrame("Add toggle button");

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

//Add first JToggleButton into JFrame
frame.add(toggleButton);

//Add second JToggleButton into JFrame
frame.add(toggleButton2);

//Set 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
************************************************************************
Related Posts Plugin for WordPress, Blogger...