我用的是
GridBagLayout
并且有一个
JList
我的定制课程。这个
列表框
正如我所期望的那样,显示了它自己,但是滚动条没有出现。(我的数据大小也大于我的
列表框
)我检查了很多相关链接,所有链接都提到了这两行代码,但这对我不起作用。
JScrollPane scrollPane = new JScrollPane(list);
add(scrollPane);
完整代码:
import java.awt.Button;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Label;
import javax.swing.*;
public class UserPart extends JFrame {
Label messageL = new Label("Confirm an item for more options.");
Button confirmB = new Button("Confirm");
Button backB = new Button("Back");
DefaultListModel model;
public UserPart() {
JList list = new JList();
model = new DefaultListModel();