setLayout public void setLayout(LayoutManager manager)By default the layout of this component may not be set, the layout of its contentPane should be set instead. For example: thisComponent.getContentPane().setLayout(new GridLayout(1, 2)) An attempt to set the layout of this component will cause an runtime exception to be thrown. Subclasses can disable this behavior. Overrides: setLayout in class Container Parameters: manager - the LayoutManager Throws: Error - if called with rootPaneChecking true See Also: setRootPaneCheckingEnabled(boolean)---------------------------------------------------------------------------------- The JFrame class is slightly incompatible with Frame. Like all other JFC/Swing top-level containers, a JFrame contains a JRootPane as its only child. The content pane provided by the root pane should, as a rule, contain all the non-menu components displayed by the JFrame. This is different from the AWT Frame case. For example, to add a child to an AWT frame you'd write: frame.add(child); However using JFrame you need to add the child to the JFrame's content pane instead: frame.getContentPane().add(child);
同意 superpig(黄飞鸿)
public void setLayout(LayoutManager manager)By default the layout of this component may not be set, the layout of its contentPane should be set instead. For example:
thisComponent.getContentPane().setLayout(new GridLayout(1, 2))
An attempt to set the layout of this component will cause an runtime exception to be thrown. Subclasses can disable this behavior. Overrides:
setLayout in class Container
Parameters:
manager - the LayoutManager
Throws:
Error - if called with rootPaneChecking true
See Also:
setRootPaneCheckingEnabled(boolean)----------------------------------------------------------------------------------
The JFrame class is slightly incompatible with Frame. Like all other JFC/Swing top-level containers, a JFrame contains a JRootPane as its only child. The content pane provided by the root pane should, as a rule, contain all the non-menu components displayed by the JFrame. This is different from the AWT Frame case. For example, to add a child to an AWT frame you'd write: frame.add(child);
However using JFrame you need to add the child to the JFrame's content pane instead:
frame.getContentPane().add(child);