我收到此错误:
randomproject.java:112: error: cannot find symbol
list.SetVisibleRowCount(5);
^
symbol: method SetVisibleRowCount(int)
location: variable list of type JList<String>
1 error
我不确定问题是什么,当我需要获取setSelectionMode,setSelectedIndex,addListSelectionListener,setLayoutOrientation等方法的实例时,我能够使用该对象的引用。
这是我的代码:
JPanel panel = new JPanel(false); //subpanel
GridBagLayout gridbag = new GridBagLayout();
panel.setLayout(gridbag);
DefaultListModel<String> listModel = new DefaultListModel<>();
listModel.addElement("element1");
listModel.addElement("element2");
listModel.addElement("element3");
listModel.addElement("element4");
JList list = new JList<>(listModel);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setSelectedIndex(0);
list.addListSelectionListener(this);
list.setLayoutOrientation(JList.VERTICAL);
list.SetVisibleRowCount(-1);
JScrollPane listScrollPane = new JScrollPane(list);
listScrollPane.setPreferredSize(new Dimension(50,50));
panel.add(list);
答案 0 :(得分:2)
我认为有一个错字。您需要致电setVisibleRowCount
而不是SetVisibleRowCount
s
应小
替换
list.SetVisibleRowCount(-1);
带
list.setVisibleRowCount(-1);
我希望这会有所帮助