When I try to put the JButton into the JList,the JBtton in the JList can't show the correct name

43 Views Asked by At
    import javax.swing.JList.*;
    import java.awt.event.*;
    import java.util.ArrayList;
    import java.awt.*;
    import javax.swing.*;
    public class test {
        static JFrame frame=new JFrame();
        //return
        static DefaultListModel lt=new DefaultListModel();
        static JList<JButton> jlt=new JList<JButton>();
        static ArrayList <JRadioButton> arr=new ArrayList<JRadioButton>();
    
        public static void main(String [] args){
            String[] arr1={"woill","dkdok","dmkm"};

            frame.setLayout(new FlowLayout(FlowLayout.LEFT));
            for(int j=0;j<3;j++){
                arr.add(new JRadioButton(arr1[j]));
            }
        
            for(int i=0;i<3;i++){
                lt.addElement(arr.get(i));
            }

            jlt.setModel(lt);
            frame.add(jlt);
            frame.setVisible(true);
        }
    }

When I try to put the JButton into the JList, it doesn't show the correct name !

Why ?

the wrong image: [enter image description here][1]

1

There are 1 best solutions below

1
Snorik On