Results 1 to 6 of 6

Thread: How to use JToggleButton class?

  1. #1
    Join Date
    Dec 2009
    Posts
    67

    How to use JToggleButton class?

    Hi All,

    I need you help to solve one of my query which is related to the java inbuilt class. I am getting troubled while understanding the 'JToggleButton class' of java. I know it is very important class for java as it handle the all concept related to the button. I you have sound knowledge about the 'JToggleButton class' of java , then please let me know the same with suitable example for it. I am waiting for you reply.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: How to use JToggleButton class?

    Hi friend,

    A JToggleButton class is used to implement two state button. There are two subclasses of JToggleButton class, and they are JCheckBox and JRadioButton. Serializable objects of JToggleButton class doesn't compatible with future Swing releases.The current serialization support of JToggleButton class is compatible with short-term storage. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package.

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How to use JToggleButton class?

    Following is the java example, which will demonstrate you the use of JToggleButton class:
    Code:
    public JToggleButton()
    JToggleButton aToggleButtonEX = new JToggleButton();
    
    public JToggleButton(Icon icon)
    JToggleButton aToggleButtonEX = new JToggleButton(new DiamondIcon(Color.PINK))
    
    public JToggleButton(Icon icon, boolean selected)
    JToggleButton aToggleButtonEX = new JToggleButton(new DiamondIcon(Color.PINK), true);
    
    public JToggleButton(String text)
    JToggleButton aToggleButtonEX = new JToggleButton("Sicilian");
    
    public JToggleButton(String text, Icon icon, boolean selected)
    JToggleButton aToggleButtonEX = new JToggleButton("Stuffed Crust",  new DiamondIcon(Color.PINK), true);
    
    public JToggleButton(Action action)
    Action action = ...;
    JToggleButton aToggleButtonEX = new JToggleButton(action);

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to use JToggleButton class?

    Hi, Following are some methods of JToggleButton class of java, please review them:
    • JToggleButton(String txt, Icon cn, boolean bn)
    • JToggleButton(String txt, Icon cn)
    • JToggleButton(String txt, boolean bn)
    • JToggleButton(String txt)
    • JToggleButton(Icon cn, boolean bn)

  5. #5
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How to use JToggleButton class?

    Hello friend,

    The following example of 'JToggleButton class' shows how to listen Events of JToggleButton using ActionListener, please study it carefully:
    Code:
    import javax.swing.JToggleButton;
    
    public class JToggleButtonDM {
      public static void main(String args[]) {
        JFrame bl = new JFrame("Selecting Toggle");
        bl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JToggleButton toggleButton = new JToggleButton("Toggle Button");
      
        ActionListener actionListener = new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            AbstractButton abstractButton = (AbstractButton) actionEvent.getSource();
            boolean selected = abstractButton.getModel().isSelected();
            System.out.println("Action - selected=" + selected + "\n");
          }
        };
     
        toggleButton.addActionListener(actionListener);
        bl.add(toggleButton, BorderLayout.NORTH);
        bl.setSize(4300, 125);
        bl.setVisible(true);
      }
    }

  6. #6
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to use JToggleButton class?

    There are number of nested class available with for JToggleButton class, see below some of them:
    1. Component: This nested class is taken from Component.BltBufferStrategy
    2. Container: This nested class is taken from Container.AccessibleAWTContainer
    3. JComponent: This nested class is taken from JComponent.AccessibleJComponent
    4. AbstractButton: This nested class is taken from AbstractButton.ButtonChangeListener

Similar Threads

  1. Replies: 8
    Last Post: 08-10-2011, 11:06 PM
  2. What is the difference between Local class and global class in C++?
    By Dëfrim in forum Software Development
    Replies: 4
    Last Post: 03-01-2011, 10:44 PM
  3. Replies: 5
    Last Post: 12-02-2010, 06:23 PM
  4. Ultra solid drives:Imation M-Class and S-Class
    By Regina in forum Portable Devices
    Replies: 1
    Last Post: 03-04-2009, 10:34 AM
  5. Good news for CBSE CLASS X & CLASS IX - visit learnnext
    By surya_expert in forum Education Career and Job Discussions
    Replies: 0
    Last Post: 13-12-2008, 12:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,262,849.62082 seconds with 17 queries