在gridBagLayout中不能完全看到按钮文本

时间:2017-07-05 07:24:57

标签: java layout gridbaglayout

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

This is ok error

这是我的布局代码。

    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);
    }

full panel 我希望有一些专家帮助解决这个问题?

1 个答案:

答案 0 :(得分:2)

一些解决方案:

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

2)从左到右依次设置按钮,并将大小设置为自动 some code