posted 19 years ago
The default layout manager for a JFrame is BorderLayout. Adding a graphic component to the center section will result in the component filling the available space. The default layout manager for a JPanel is FlowLayout which will ask the graphic component for it's preferred size (something that you could do, too). If the graphic component doesn't have any way of returning a Dimension that it considers desirable then the FlowLayout may not have much to work with. The default size for a JPanel is (10, 10). One thing you could do is to set the layout manager in the JPanel to a layout that ignores the preferred size of the graphic component and will expand it to fill the available space. Possibilities include the center section of a BorderLayout, GridLayout initialized to (0,1), and GridBagLayout with both weight constraints set to non–zero and the fill constraint set to GridBagConstraints.BOTH.