错误:找不到符号(JList,list.SetVisibleRowCount(int))

时间:2014-02-12 06:02:33

标签: java swing

我收到此错误:

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);

1 个答案:

答案 0 :(得分:2)

我认为有一个错字。您需要致电setVisibleRowCount而不是SetVisibleRowCount s

替换

list.SetVisibleRowCount(-1);

list.setVisibleRowCount(-1);

我希望这会有所帮助