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]](https://i.stack.imgur.com/qiTy6.png)
perhaps you are thinking along the lines of a ComboBox with a ListCell Renderer, as described here?
https://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html#renderer https://docs.oracle.com/javase/tutorial/uiswing/components/list.html#mutable