javaswingjlistjscrollbar

How to set size of JList with Scrollbar in swing?


How to set scrollbar in JList and how to set the size of JList. I have a jList and in JList I want to set fix height. If I have data more then that height I want to show a scrollbar.


Solution

  • To set a JLit in scrollbar

    JList<Object> list =  new JList<Object>();
    JScrollPane sp = new JScrollPane(list);
    

    To size the JList

    list.setPreferredSize(new Dimension(200, 200));