I'm trying to insert a design of a frame to put it inside a Jlist, but it throws me this error java.lang.IllegalArgumentException: adding a window to a container
public class clsRender implements ListCellRenderer, Renderer{
private final JTextField observacion;
private final JLabel fecha;
private final jfrmGestion gestion;
public clsRender() {
this.gestion = new jfrmGestion();
this.observacion = gestion.getjTextField1();
this.fecha = gestion.getjLabel1();
}
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
String [] valor = value.toString().split("/");
observacion.setText(valor[0]);
fecha.setText(valor[1]);
if(!isSelected){
gestion.setBackground(list.getBackground());
}
else{
gestion.setBackground(list.getSelectionBackground());
}
return gestion;
}
@Override
public void setValue(Object aValue, boolean isSelected) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Component getComponent() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
That's the class I was designing with, but I do not know why this error occurs
private void CargarDatos(){
ListHistorial.setCellRenderer(new clsRender());
model = new DefaultListModel();
ListHistorial.setModel(model);
}
private void LlenarHistorial(){
try {
cn = conecta.Conectar();
stmt = cn.createStatement();
rs = stmt.executeQuery("SELECT * FROM tb_observaciones WHERE id_alquiler = "+id_alquiler);
while(rs.next()){
String observacion = rs.getString(2);
Date fecha = rs.getDate(4);
model.addElement(observacion+"/"+fecha);
}
cn.close();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Error al cargar los datos del sistema");
}
}