当我运行我的代码时,JList显示但它确实很小,当我尝试改变它的大小时,它不会改变大小。我做错了什么?很多GUI格式对我来说都是新的。感谢。
public class Panel extends JPanel
{
//Fields
private Dimension dimensions;
private JButton button1;
private JList list;
private JScrollPane listScroller;
private String title;
private DefaultListModel model;
/**
* Constructor
*/
public Panel()
{
dimensions = new Dimension(400, 300);
setPreferredSize(dimensions);
setBackground(Color.WHITE);
setLayout(null); //Lets me lay my components out freely
button1 = new JButton("New Set");
button1.setBounds(new Rectangle(new Point(150, 250), button1.getPreferredSize()));
button1.addActionListener(new ButtonListener());
add(button1);
String[] titleArray ={title};
model = new DefaultListModel();
for(String title :titleArray)
{
model.addElement(title);
}
list = new JList(model);
list.setBounds(new Rectangle(new Point(200,200), list.getPreferredSize()));
add(list);
listScroller = new JScrollPane(list);
listScroller.setBounds(new Rectangle(new Point(200,200), listScroller.getPreferredSize()));
add(listScroller);
}
}