How to change color, font and size of JRadioButton text in java swing?

When we construct a JRadioButton with some text, that text comes with default format. Many times we need to change the font, color and size properties of the JRadioButton text. Its very easy to do it, lets check it how with example below :

1. Lets see , when we create the JRadioButton how it looks :
JFrame radioFrame = new JFrame("JRadioButton text example ");
        radioFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JRadioButton radioEx = new JRadioButton("Radio button text example");
        radioFrame.getContentPane().add(radioEx, BorderLayout.CENTER);
        radioFrame.pack();
        radioFrame.setVisible(true);



2. Now we need to change the String which we pass to the JRadioButton, we are going to append and font properties which we set in html.
JRadioButton radioEx = new JRadioButton("Radio button text example");



Similarly we can do some change to the text for other swing components such as JLabel, JButton, JCheckBox etc.
Simply using we can change the properties such as Font type, Font color and Font size.


Share on Google Plus

About Pranav

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment