我有一个扩展 JPanel 的类。下面的代码:
public class Test extends JPanel implements Testnterface {
private JScrollPane listScroller;
DefaultListModel model;
private JList requestList;
public Test() {
String title = "Stackoverflow Question";
setBorder(BorderFactory.createTitledBorder(title));
model = new DefaultListModel();
requestList = new JList(); // create a list
listScroller = new JScrollPane(requestList); // create a scrollbar to the list
listScroller.setPreferredSize(new Dimension(250, 80));
setLayout(null);
add(listScroller); // even though I add the scrollPane, nothing is displayed
}
}
我更新了代码。即使我添加了它,我似乎也无法让我的 JScrollPane 显示在我的 JPanel 上。有人有什么想法吗?