有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Gridlayout未根据约束调整大小

    this.setSize(700,500);
    this.setLayout(new BorderLayout());
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setIconImage(frameIcon.getImage());
    this.setTitle("Rifle Reload Logger v1.0");
    this.setMinimumSize(new Dimension(700,500));
     /*
    * The center panel of the JFrame will be used to display the current information
    * as needed whether it be for showing the file chooser, or the reload data.*/
    center.setVisible(true);
    center.setLayout(new GridLayout(6,4));
    this.add(center, BorderLayout.CENTER);
    setGUILabels();//sets the labels for the entire Gui.

本质上,我这里的问题是我的GridLayout没有创建我要求的6x4大小。它的尺寸是6x3,这是一张图片Improper gridlayout.


共 (1) 个答案

  1. # 1 楼答案

    您只向中心JPanel添加了18个组件,而不是24个。如果需要4列和可变行数,请将GridLayout设置为new GridLayout(0, 4)