Andre Uhres wrote:With JPanel(null)
I suggest writing a new LayoutManager class that has an empty layoutComponent body but does have an implementation for preferredSize, that returns a Dimension such that all objects fit within that panel. It basically returns a Dimension(width, height), where width is the maximum of c.getX() + c.getPreferredSize().width and height is the maximum of c.getY() + c.getPreferredSize().height, for all child components c.
This way your panel will work better in JScrollPanes.
Olivier Legat wrote:Excellent! Thank-you so much this is exactly what I needed. I just don't quite understand the purpose of this Runnable interface though. Why must you catch an exception and what is this UIManager? :?
Nearly all updates to the user interface should be done on the Event Dispatcher
Thread, and that includes creating your user interface. That's what SwingUtilities.invokeLater and SwingUtilities.invokeAndWait can do for you.
UIManager is a utility class that can help you with the overall look and feel of your components. This example tries to set the system look and feel, so the application will look like a Windows application when run in a Windows environment, and a GTK (mostly) if run in a Linux environment. However, this method can throw some checked exceptions, so you must catch these. Although the catch-all and ignoring is a bad idea, in this example it doesn't really matter because the only difference will be the way your application looks.
Although
you should still print the exception.