所以我正在列出之前玩过这些游戏的玩家的名单。我遇到的问题是,在名称列表变得太长而没有滚动之后,列表没有向其添加滚动窗格。我试图以这种方式实现滚动条,但没有成功。我做错了什么?
Insets insets = pane.getInsets();
Dimension size = Player1.getPreferredSize();
Player1.setBounds(90 + insets.left, 50 + insets.top, 250, 40);
size = Player2.getPreferredSize();
Player2.setBounds(450 + insets.left, 50 + insets.top, 250, 40);
size = P1List.getPreferredSize();
P1List.setBounds(90 + insets.left, 100 + insets.top, 250, 350);
size = P2List.getPreferredSize();
P2List.setBounds(450 + insets.left, 100 + insets.top, 250, 350);
Ok.setBounds(650 + insets.left, 500 + insets.top, 100, 30);
size = Ok.getPreferredSize();
final JScrollPane sp1 = new JScrollPane();
sp1.setViewportView(P1List);
final JScrollPane sp2 = new JScrollPane();
sp2.setViewportView(P2List);
pane.add(Player1);
pane.add(Player2);
pane.add(P1List);
pane.add(P2List);
pane.add(sp1);
pane.add(sp2);
pane.add(Ok);