小编May*_*May的帖子

创建JButtons的行和列

我被赋予了创建3组座位的任务,每组有3排10列座位.首先,我开始为三组创建一个座位,我现在正尝试使用布局管理器以JButtons3x10的样式显示座位(这些).这是我的代码:

public class ConcertPanel extends JPanel
{
    private JPanel Panel1;
    private JButton goldSeat;
    private JButton silverSeat;
    private JButton bronzeSeat;


   ConcertPanel()
   {   
        Panel1 = new JPanel();
        Panel1.setSize(500,500);

                setLayout(new GridLayout(rows, cols));
                for(int i = 0; i < rows; i++)
                for(int j = 0; j < cols; j++)
            {
                goldSeat = new JButton();
                silverSeat = new JButton();
                bronzeSeat = new JButton();
                add(new JButton());
            }
                this.add(Panel1);

       }
}
Run Code Online (Sandbox Code Playgroud)

在那一刻我只是在jpanel中得到30个按钮,它们不在行或列中?救命 :(

java swing button layout-manager

2
推荐指数
1
解决办法
1601
查看次数

标签 统计

button ×1

java ×1

layout-manager ×1

swing ×1