Use of jRadioButton and Change jRadioButton Style in Java NetBeans

If you want to use jRadioButton in Java and want to change Style or create Stylish jRadioButton in Java, you have to use simple steps on you programming in java. So, let's find How to add image in jRadioButton and what style we use to make attractive jRadioButton in Java. 

You can say jRadioButton as Option Button in Java.
Different look of jRadiobutton
jRadioButton's Looks

How to Set Background image in jFrame in Swing Java?


 Default jRadioButton to Graphical jRadioButton:

First of all you have to create some image just look like radio button. For designing it, you can use PowerPoint or googling image and modify according to your desire look.

Or you can save following:

OptionButton’s icon category 1: JOption1 for set icon  JOption1 icon for focus  JOption1 icon for select

OptionButton’s icon category 2: JOption2 for set icon  JOption2 icon for focus  JOption2 icon for select

OptionButton’s icon category 3: JOption3 for set icon  JOption3 icon for focus  JOption3 icon for select


These above images are in PNG format with transparent background, you can right click and save it and use it on your project.

After designing and creating image, just go to your Project’s Package and copy all images and paste it on package.
copy files in java package process
Copy Files in java package

When you will copy these option button image, you have to proceed with following point.

GUI Project Design in Java Netbeans


 Add image in jRadioButton for front view:
➤ First switch to jRadioButton’s Properties screen of NetBeans IDE.

➤ Find “icon” option and select your Image.

➤ Then press "OK" button. and the desire image will work as main option button.


 Add image for Focus or Hover Style Image in jRadioButton:
➤ In Properties screen of NetBeans IDE, find “rolloverIcon” option.

➤ And Browse your desire Icon for hover style of jRadioButton.

It will change during focus on Option button control.


 Add Image for Select Option Style in jRadioButton:
➤ Just same find option “selectedIcon”.

➤ After that select you image you have created. And press "OK" button.

The following picture defines all steps.
Set image icon in jradiobutton
Different types of icons selection Process
So, this way you can easily change look and feel of jRadioButton in java.

Auto Resizing Controls or Component Settings in Java Netbeans


 How to Change Look of jRadioButton through Code in Java Swing? 

If you want to proceed through coding during runtime change process, here is the following way.
Define all icon in Application’s initComponents events.

public JRadioButton_Look() { 
        initComponents();
        try{
              // Here MyOptionBtn1 is jRadioButton.
              BufferedImage imgico = ImageIO.read(getClass().getResource("JBtn1.png"));
              MyOptionBtn1.setIcon(new ImageIcon(imgico));
        
              BufferedImage imgicofocus = ImageIO.read(getClass().getResource("JBtn1_Focus.png"));
              MyOptionBtn1.setRolloverIcon(new ImageIcon(imgicofocus));
              // setRolloverIcon is for when your cursor move on it or focus on it.
        
              BufferedImage imgicoselect = ImageIO.read(getClass().getResource("JBtn1_select.png"));
              MyOptionBtn1.setSelectedIcon(new ImageIcon(imgicoselect));
              // setSelectedIcon is for when you select this option.

         }catch(Exception ex1){}
       
    }

There is another long way through code where you have to write code in control’s FocusGained, FocusLost, MouseMoved, ItemStateChanged events. After that you will find same look wise process in it.


 How to Set Transparent Background of jRadioButton?

When you drag jRadioButton, it will present in background default color after changing the icon it will contain the background default color as shown bellow.
Default background color of RadioButton
Default background color
So, the point is that how to Set Transparent Background in jRadioButton?

The solution is that you have to unchecked the “opaque” option from “Properties” screen. And the magic will present. The background color will be invisible just same as define following.
Transparent background of RadioButton
Transparent background Process
So, you can understand easily that in Java, you can change look of jRadioButton in Java Swing through image with SKOTechLearn Tips.

How to use jList to Show Data or Items in Netbeans

0 comments: