【发布时间】:2013-11-28 05:06:26
【问题描述】:
我在尝试将 JList 添加到面板的 WEST 侧时遇到问题。
通过使用另一个面板并将其添加到原始面板,我能够在 NORTH 上成功添加文本字段和搜索按钮。
JPanel panelShop = new JPanel();
// Example of items in the scrollbar list
String[] results = { "Result 1", "Result 2", "Result 3", "Result 4"};
JList searchList = new JList(results);
searchList.setLayoutOrientation(JList.VERTICAL);
// Sets the number of items to display without requiring to scroll
//searchList.setVisibleRowCount(4);
panelShop.add(searchList, BorderLayout.WEST);
问题是最后一行代码,当我试图将 JList 添加到原始面板的 WEST 边框时。
什么都没有。
谢谢!
【问题讨论】:
-
如需尽快获得更好的帮助,请发帖SSCCE。
-
我把它缩短...这样更好吗?
-
它不是自编译的。
-
我应该如何让你编译我的代码而不在这里发布长代码?
-
去掉所有多余的废话。我可以将列表添加到组件中,将其放入面板中,然后在 20 LOC 内将其显示在屏幕上。
标签: java swing layout jpanel jlist