我想指定我的 JList 的固定宽度
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS));
Panel panel = new JPanel();
panel.setBackground(Color.WHITE);
getContentPane().add(panel);
String [] queries = {"a", "b", "a", "b" , "a", "b", "a", "b"};
panel.setLayout(new BorderLayout());
JList list = new JList(queries);
list.setMaximumSize(new Dimension(200, 200)); // this line does not do the job
list.setMinimumSize (new Dimension (200,200));
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setVisibleRowCount(5);
JScrollPane scrollPane_1 = new JScrollPane(list);
panel.add(scrollPane_1 , BorderLayout.CENTER);
但这并不强制大小为200 200
. 我需要宽度为JScrollPane
200