我添加了主面板,然后添加到按钮面板。根据复选框,选择并取消选择我更改按钮文本。但是一个文字不完全可见。
这是我的布局代码。
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);
}