【问题标题】:Button text not visible fully in gridBagLayout按钮文本在 gridBagLayout 中不完全可见
【发布时间】:2017-12-08 17:30:30
【问题描述】:

我添加了主面板,然后添加到按钮面板。根据复选框,选择和取消选择我更改按钮文本。但是一个文本没有完全可见。

这是我的布局代码。

    public RestartTreatmentDialog()
  {
    final GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.columnWidths = new int[] { 0, 0 };
    gridBagLayout.rowHeights = new int[] { 0, 0, 0 };
    gridBagLayout.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
    gridBagLayout.rowWeights = new double[] { 1.0, 0.0, Double.MIN_VALUE };

    getContentPane().setLayout(gridBagLayout);

    final GridBagConstraints gbc_panel = new GridBagConstraints();
    gbc_panel.insets = new Insets(0, 0, 5, 0);
    gbc_panel.fill = GridBagConstraints.BOTH;
    gbc_panel.gridx = 0;
    gbc_panel.gridy = 0;

    getContentPane().add(getTopPanel(), gbc_panel);

    final GridBagConstraints gbc_panel_1 = new GridBagConstraints();
    gbc_panel_1.fill = GridBagConstraints.VERTICAL;
    gbc_panel_1.gridx = 0;
    gbc_panel_1.gridy = 1;

    getContentPane().add(getButtonPanel(), gbc_panel_1);
  }

这是按钮面板。

if (buttonPanel == null)
    {
      buttonPanel = new Panel();

      final GridBagLayout gbl_buttonPanel = new GridBagLayout();
      gbl_buttonPanel.columnWidths = new int[] { 0, 0, 0 };
      gbl_buttonPanel.rowHeights = new int[] { 0, 0 };
      gbl_buttonPanel.columnWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
      gbl_buttonPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };

      buttonPanel.setLayout(gbl_buttonPanel);

      final GridBagConstraints gbc_button = new GridBagConstraints();
      gbc_button.insets = new Insets(0, 0, 5, 5);
      gbc_button.gridx = 0;
      gbc_button.gridy = 0;

      buttonPanel.add(getRestartButton(), gbc_button);

      final GridBagConstraints gbc_button_1 = new GridBagConstraints();
      gbc_button_1.insets = new Insets(0, 0, 5, 0);
      gbc_button_1.gridx = 1;
      gbc_button_1.gridy = 0;

      buttonPanel.add(getCancelButton(), gbc_button_1);
    }

我期待一些专家的帮助来解决这个问题?

【问题讨论】:

    标签: java layout gridbaglayout


    【解决方案1】:

    一些解决方案:

    1) 为你的左键设置一个更大的尺寸,所以当你改变尺寸时你没有问题some code

    2) 从左到右调整按钮并将大小设置为自动 some code

    【讨论】:

    • 我没有说得太详细,因为我没有从你的解释中理解你使用的是 SWING 还是 JAVAFX
    • Francesco,我用的是 SWING。
    猜你喜欢
    • 1970-01-01
    • 2011-08-10
    • 2023-03-16
    • 2021-04-27
    • 2020-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-23
    相关资源
    最近更新 更多