Thursday, June 20, 2019

Change Look of jRadioButton in Java Swing NetBeans through Image

Change Look of jRadioButton in Java Swing NetBeans through Image

In this article SKOTechLearn Tips will show you the features of jRadiobutton, In java you can design your controls or swing controls according to your need. We will learn how to change different types of look of jRadiobutton in java Netbeans through image .
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 you 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 it,  come to following points.

GUI Project Design in Java Netbeans

 Add image for front view:
Now go to you jRadioButton’s Properties screen.
Find “icon” option and select your front view image. according to desire.

 Add image for Focus:
In Properties screen, find “rolloverIcon” option.
And select focus icon from here.

It will change during focus on control.

 Now last, add icon when you select it:
Just same find option “selectedIcon”. And add picture you have created.

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() { 
       // Here MyOptionBtn1 is jRadioButton.
        BufferedImage imgico ="JBtn1.png"));
        MyOptionBtn1.setIcon(new ImageIcon(imgico));
         BufferedImage imgicofocus ="JBtn1_Focus.png"));
        MyOptionBtn1.setRolloverIcon(new ImageIcon(imgicofocus));
        // setRolloverIcon is for when your cursor move on it or focus on it.
         BufferedImage imgicoselect ="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