So i want to somehow set the size of my JOptionPane - without setting it, it is just too large for my purposes and won't look nice. here is my code:
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);
when i set the size of the JPanel as such:
panel.setPreferredSize(new Dimension(500, 200));
the scroll bar disappears and hence not everything is displayed.
any ideas? Java n00b...
Please do the following changes and see;
Do not put the JScrollPane within another Panel. Pass the JScrollPane directly within the showMessageDialog().
Also use scrollPane.getViewport().add(list);
EDIT: I just tried the following, and the scroll bar is visible for me as the items increased.
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"
,"6. Extended Family","7. Extended Family","8. Extended Family","9. Extended Family"};
JList list = new JList(categories);
scrollpane = new JScrollPane(list);
JPanel panel = new JPanel();
panel.add(scrollpane);
scrollpane.getViewport().add(list);
JOptionPane.showMessageDialog(null, scrollpane, "Error List",
JOptionPane.PLAIN_MESSAGE);
screenshot attached;