所以我想以某种方式设置我的 JOptionPane 的大小 - 如果不设置它,它对于我的目的来说太大了,而且看起来不太好。这是我的代码:
JScrollPane scrollpane = new JScrollPane();
String categories[] = { "1. Problem One Problem One Problem One Problem One Problem One Problem One Problem One Problem One Problem One", "2. Problem Two", "3. Extended Family", "4. Extended Family", "5. Extended Family"};
JList list = new JList(categories);
errorListCellRenderer cellRenderer = new errorListCellRenderer();
list.setCellRenderer(cellRenderer);
scrollpane = new JScrollPane(list);
JPanel panel = new JPanel();
panel.add(scrollpane);
JOptionPane.showMessageDialog(null, panel, "Error List",
JOptionPane.PLAIN_MESSAGE);
当我这样设置JPanel的大小时:
panel.setPreferredSize(new Dimension(500, 200));
滚动条消失,因此并未显示所有内容。
有任何想法吗?爪哇n00b...