Swing jList usage

Submitted by code_admin on Fri, 07/20/2018 - 12:52

Tricky setup of jList

  1.     private JScrollPane jScrollPane = new JScrollPane();
  2.     private DefaultListModel jListModel = new DefaultListModel();
  3.     private JList jList1 = new JList();
  4.  
  5. ...
  6.  
  7. in init:
  8.         jList1.setModel(jListModel);
  9.         jList1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
  10.         jList1.setLayoutOrientation(jList1.VERTICAL);
  11.         jList1.setVisibleRowCount(-1);
  12.  
  13.         jScrollPane.add(jList1);
  14.         jScrollPane.getViewport().add(jList1, null);
  15.         jScrollPane.setPreferredSize(new Dimension(250, 80));

Tags

RJM Article Type
Work Notes