You need to make a list containing JPanel panels, which include an image, text and checkbox.

List

Like this, only under each need checkboxes.

I tried this:

 public static JList<JPanel> itemsArray; public static DefaultListModel<JPanel> listModel; 

But after adding, it’s not a socket that is added, but a debug presentation (I don’t know how to call it exactly) So here’s:

Debug view

For each item, I want to use a separate ItemComponent class ItemComponent

The number of elements may be unlimited and not known in advance. Plus they should be added dynamically.

  • Make a panel with all these elements and JScrollPane in the JScrollPane . - zRrr
  • @zRrr number of elements not known in advance - Herrgott
  • I think it may be appropriate to make the List <GridPane>. In each element of the grid, in one column to create the elements you need. - Mikhail Ketov
  • @Herrgott You can write your own implementation of ListCellRenderer , which will have the necessary components in the correct position, the problem is that the elements of the JList are images, not full-fledged components, as for example. in Android, i.e. You can add a button or checkbox to the renderer, but by themselves they will not be pressed, spawn events, etc. Therefore, they use either JTable with TableCellRenderer and TableCellEditor , or their own panel, on which the components are laid out, as desired. - zRrr

1 answer 1

 final JPanel panel = new JPanel(); final File list[] = new File("./pictures/").listFiles(); assert list != null; for (File aList : list) { final JLabel label = new JLabel(); label.setText("my icon"); panel.add(label); try { label.setIcon(new ImageIcon(ImageIO.read(aList))); } catch (IOException e) { e.printStackTrace(); } } 

I hope I understand you correctly, what do you want to do