JRadioButton: how to replace text by IconImage?

前端 未结 4 1686
不思量自难忘°
不思量自难忘° 2021-01-13 10:22

I want to replace the text in my radio button list by an icon.

I\'ve tried this:

rotateButton = new JRadioButton(rotateIcon.getImage());
4条回答
  •  长发绾君心
    2021-01-13 10:59

    There is no radio button constructor that allows an image as the content argument instead of a text. The only way to replace the text of a radio button by an image it is generate html and pass it as an argument to the default constructor.

    import javax.swing.*;
    
    class RadioWithImage {
    
        public static void main(String[] args) throws Exception {
            URL url = Windows_ChordsGenerator.class.getResource("/images/img1.png");
    
            final String html = "";
    
            JRadioButton radioButton = new JRadioButton(html);     
           }
    }
    

提交回复
热议问题