2 回答
TA贡献1719条经验 获得超6个赞
首先,您应该使用布局管理器来避免此类问题。当您出于某些原因想要避免使用它们时,您必须为您使用的滚动窗格提供大小。
frame2 = new JFrame();
frame2.setBounds(100, 100, 543, 432);
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.getContentPane().setLayout(null);
JList list = new JList(names);
list.setVisibleRowCount(10);
JScrollPane scroller = new JScrollPane(list);
scroller.setBounds(36, 11, 161, 345);
frame2.getContentPane().add(scroller);
JList list_1 = new JList(access);
list_1.setVisibleRowCount(10);
scroller = new JScrollPane(list_1);
scroller.setBounds(356, 11, 161, 345);
frame2.getContentPane().add(scroller);
frame2.setVisible(true);
TA贡献1865条经验 获得超7个赞
那些JLists 不会因为组件顺序不正确而猛增,在这里试试这个。
setBounds()从JLists 中移除并设置JScrollPanes 的边界。然后添加列表以滚动窗格。
JFrame frame2 = new JFrame();
frame2 = new JFrame();
frame2.setBounds(100, 100, 543, 432);
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.getContentPane().setLayout(null);
JList list = new JList(names);
list.setVisibleRowCount(10);
JScrollPane jScrollPane = new JScrollPane(list);
jScrollPane.setBounds(36, 11, 161, 345);
frame2.getContentPane().add(jScrollPane);
JList list_1 = new JList(access);
list_1.setVisibleRowCount(10);
JScrollPane jScrollPane1 = new JScrollPane(list_1);
jScrollPane1.setBounds(356, 11, 161, 345);
frame2.getContentPane().add(jScrollPane1);
frame2.setVisible(true);
添加回答
举报