如果我有这样的代码:
class X extends JFrame
{
X()
{
setLayout(new GridLayout(3,3));
JButton b = new JButton("A-ha");
/*I would like to add this button in the center of this grid (2,2)*/
//How can I do it?
}
};
最佳答案
据我所知,您必须填写之前的所有单元格。所以你需要先添加4个组件,然后才能添加中心组件。嗯,它可能是一个更好的布局管理器。
你想做什么?也许BorderLayout是你要找的吗?
关于java - 如何将 JButton 添加到 GridLayout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2817739/