in my app I use a JList with JScrollpane to show an action log.
For this I do:
logModel = new DefaultListModel();
logModel.ensureCapacity(300);
logList = new JList(logModel);
logList.setPreferredSize(new Dimension(300, 150));
logList.setVisibleRowCount(6);
JScrollPane sp = new JScrollPane(logList);
sp.setHorizontalScrollBar(null);
GridBagConstraints gbc_logList = new GridBagConstraints();
gbc_logList.anchor = GridBagConstraints.WEST;
gbc_logList.gridx = 0;
gbc_logList.gridy = 6;
gbc_logList.weightx = 1.0;
gbc_logList.weighty = 0.5;
gbc_logList.gridwidth = 3;
pane.add(sp, gbc_logList);
But If I start to add the items the list only show max. 9 items in the list. But the model reported the size in the right size (as sample 11)
I add a sequence like
private void createFolderSequence() {
logModel.add(logModel.getSize(), "Create Folder: JNIFolder in root");
int res = createFolder("JNIFolder", "/");
logModel.add(logModel.getSize(), "Created: " + Integer.toString(res));
logModel.add(logModel.getSize(), "Create Folder: JNIFolder2 in /JNIFolder/");
res = createFolder("JNIFolder2", "/JNIFolder/");
logModel.add(logModel.getSize(), "Created: " + Integer.toString(res));
logModel.add(logModel.getSize(), "Rename Folder: JNIFolder2 to NIFolder3");
res = renameFolder("/JNIFolder/JNIFolder2","JNIFolder3");
logModel.add(logModel.getSize(), "Renamed: " + Integer.toString(res));
logModel.add(logModel.getSize(), "Remove Folder: JNIFolder2");
res = removeFolder("/JNIFolder/JNIFolder2");
logModel.add(logModel.getSize(), "Removed: " + Integer.toString(res));
System.out.println(logModel.getSize());
logModel.add(logModel.getSize(), "Remove Folder: JNIFolder3");
logModel.add(logModel.getSize(), "Remove Folder: JNIFolder3");
res = removeFolder("/JNIFolder/JNIFolder3");
logModel.add(logModel.getSize(), "Removed: " + Integer.toString(res));
System.out.println(logModel.getSize()); //Print 11
}
The console shows at last 11 but only 9 items are inside the list, also if I scroll down.
Any Idea what I do wrong or what i missed?
question from:
https://stackoverflow.com/questions/65559799/jlist-only-show-9-items 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…