How to Create Radio Button by Java Swing & Use Radio Button


Introduction

The class JRadioButton is associate degree implementation of a radio button - associate degree item which will be selected  or deselected, and that displays its state to the user.
Class Declaration

Following is that the declaration for javax.swing.JRadioButton category −

public category JRadioButton
   extends JToggleButton
      implements Accessible

Class Constructors
Sr.No.     Constructor & Description
1    

JRadioButton()

Creates an initially unselected radio button with no set text.
2    

JRadioButton(Action a)

Creates a radiobutton where properties are taken from the Action supplied.
3    

JRadioButton(Icon icon)

Creates an initially unselected radio button with the specified image but no text
4    

JRadioButton(Icon icon, boolean selected)

Creates a radio button with the specified image and selection state, but no text.
5    

JRadioButton(String text, boolean selected)

Creates a radio button with the specified text and selection state.
6    

JRadioButton(String text, Icon icon)

Creates a radio button that has the specified text and image, and which is initially unselected.
7    

JRadioButton(String text, Icon icon, boolean selected)

Creates a radio button that has the specified text, image, and selection state.
Class Methods
Sr.No.     Method & Description
1    

AccessibleContext getAccessibleContext()

Gets the AccessibleContext associated with this JRadioButton.
2    

String getUIClassID()

Returns the name of the L&F class that renders this component.
3    

protected String paramString()

Returns a string representation of this JRadioButton.
4    

void updateUI()

Resets the UI property to a value from the current look and feel.
Methods Inherited

This class inherits methods from the following classes −

    javax.swing.AbstractButton
    javax.swing.JToggleButton
    javax.swing.JComponent
    java.awt.Container
    java.awt.Component
    java.lang.Object

JRadioButton Example

Create the following Java program using any editor of your choice in say D:/ > SWING > com > tutorialspoint > gui >

SwingControlDemo.java

package com.tutorialspoint.gui;

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

public class SwingControlDemo
   public static void main(String[] args)
   private void prepareGUI()
How to Create Radio Button by Java Swing & Use Radio Button How to Create Radio Button by Java Swing & Use Radio Button Reviewed by Learn Programming on 12:11:00 AM Rating: 5

No comments:

Powered by Blogger.