为什么我不能再将布局设置为 GridBagLayout?



当我将布局设置为GridBagLayout时,我遇到了一个错误,但它以前工作得很好。

import javax.swing.*;
import java.awt.*;
public class GridBagLayoutTest {
public static void main (String [] args)
{
JFrame frame = new JFrame();
frame.setLayout(new GridBagLayout()); 
}
}

我得到一个错误说:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
The method setLayout(LayoutManager) in the type JFrame is not applicable for the arguments (GridBagLayout)

您必须导入java.awt包,因为GridBagLayout类属于该包。

最新更新