0

I have a JList with a DefaultListModel and a JScrollPane for vertical scrolling in it:

private DefaultListModel<DMatrixSet> drawingsModel = new DefaultListModel<>();
private JList<DMatrixSet> drawings = new JList<>();
private JScrollPane scrollPane = new JScrollPane();

This is how I set them up:

    drawings.setBounds(30 + ENTRY_WIDTH, 40 + 10, ENTRY_WIDTH, ENTRY_HEIGHT);

    getContentPane().add(scrollPane);

    scrollPane.setBounds(30 + ENTRY_WIDTH*2, 40 + 10, 15, ENTRY_HEIGHT);
    scrollPane.getViewport().add(drawings);

    drawings.setModel(drawingsModel);

The problem is: the scroll pane simply does not work. It can't be scrolled nor somehow used. I add 30 elements to the list after init:

    for (int i = 0; i < 30; i++)
        drawingsModel.addElement
    (new DMatrixSet("test" + i, 1, 1));

And this is what I can see:

sc001

I cannot scroll nor somehow interact with the scroll pane, and can so can only see the first 14 elements of the list.

German Vekhorev
  • 339
  • 6
  • 16
  • Why do you set bounds for jscrollpane and jlist. Get rid of them and see if its working – Jay Smith Dec 31 '17 at 18:12
  • I've never seen getViewport used for the scroll pane - try just adding it directly? – APerson Dec 31 '17 at 18:13
  • 1. For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2. *"`drawings.setBounds(..`"* Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). – Andrew Thompson Dec 31 '17 at 18:36

0 Answers0