如何将JButton添加到一个循环内的gridlayout中的特定位置?

时间:2013-11-09 20:49:41

标签: java layout grid jbutton frame

我正在尝试将JButtons添加到gridlayout上的指定位置,但我不知道该怎么做,现在我已经

public void addButtons()
    {
        myBoard = myController.getMyBoard();
        for (int i = 0; i < this.getEntryInt(); i++)
        {
            for(int j = 0 ; j < this.getEntryInt(); j++)
            {


                if(myBoard[i][j]==true)
                {
                    buttons[i][j] = new JButton("Q"); // error: The type of the expression must be an array type but it resolved to JButton

                }
            }
        }
    }

有没有办法在网格布局中为特定情节添加按钮?

1 个答案:

答案 0 :(得分:1)

您无法选择将组件放在GridLayout中的位置。它们将连续添加。

请尝试使用GridBagLayout