简体   繁体   中英

Why can't I set my layout to GridBagLayout anymore?

I'm getting an error when I set my layout to GridBagLayout but it worked just fine before.

import javax.swing.*;
import java.awt.*;

public class GridBagLayoutTest {
public static void main (String [] args)
{
    JFrame frame = new JFrame();
    frame.setLayout(new GridBagLayout()); 
}

}

I'm getting an error saying:

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)

You have to import java.awt package since GridBagLayout class belongs to that package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM