Sunday 12 April 2015

Filled Under:

Simple JToggle Button In Java

Toggle button is specially used when we want to stop or start some process as happen in stop watch.In This example we have created simple toggle button it will not perform any action if you want to perform some action with toggle button then see our tutorial How to operate toggle button . Common Constructor of JToggleButton are given below in general forms

public JToggleButton(Action a)

public JToggleButton(String text,Icon icon)

public JToggleButton(String text,Icon icon,boolean selected)

CODING:


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class myframe extends JFrame 
{

myframe()
{

setTitle("Simple JToggleButton");
setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JToggleButton jb = new JToggleButton("Toggle Button");
jb.setPreferredSize(new Dimension(150,50));
add(jb);
setSize(700, 200);
setVisible(true);

  
}

public class tooggle
{

public static void main(String[] args) {

myframe x = new myframe();
}
}

OUTPUT:


0 comments:

Post a Comment