如何在 java swing 中创建 3 个按钮,以占据它们被添加到的面板的 1/3


private JPanel createControlPanel() {
    JPanel ctrl = new JPanel();
    addBorder(ctrl,"Controls");
    //add 3 buttons here
    return ctrl;
    }

我想创建这 3 个按钮并将它们添加到 ctrl

从文档中:

GridLayout experimentLayout = new GridLayout(1,3);
compsToExperiment.setLayout(experimentLayout);
compsToExperiment.add(new JButton("Button 1"));
compsToExperiment.add(new JButton("Button 2"));
compsToExperiment.add(new JButton("Button 3"));

医生

最新更新