دنبال کننده ها

۱۳۹۶ دی ۱۰, یکشنبه

java - JScrollPane doesn't work with JList

[ad_1]



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




[ad_2]

لینک منبع