我在Composite
上遇到了一些麻烦。我已经编写了以下代码:
final Composite mavniOptionsComposite = new Composite(parent, SWT.NONE);
mavniOptionsComposite.setLayout(new GridLayout(3, false));
final GridData textGridData = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
final Label mavniFormatingLabel = new Label(mavniOptionsComposite, SWT.None);
mavniFormatingLabel.setText(PFT.MAVNI_HISTORY.getExplanationLabelText());
mavniFormatingLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
final GridData mavniFormatingGridData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
final Button mavniHistoryRunCheckbox = new Button(mavniOptionsComposite, SWT.CHECK);
mavniHistoryRunCheckbox.setLayoutData(mavniFormatingGridData);
mavniHistoryRunCheckbox.setText(PFT.MAVNI_HISTORY.getExplanationLabelText());
mavniHistoryRunCheckbox.addSelectionListener(new mavniHistoryCheckBoxSelectionAdapter());
widgetsMap.put(PFT.MAVNI_HISTORY, mavniHistoryRunCheckbox);
final Button mavniRealtimeCheckbox = new Button(mavniOptionsComposite, SWT.CHECK);
mavniRealtimeCheckbox.setLayoutData(mavniFormatingGridData);
mavniRealtimeCheckbox.setText(PFT.MAVNI_REALTIME.getExplanationLabelText());
mavniRealtimeCheckbox.setEnabled(MyPreferences.isWmcDefined());
widgetsMap.put(PFT.MAVNI_REALTIME, mavniRealtimeCheckbox);
final Label toolNameLabel = new Label(mavniOptionsComposite, SWT.NONE);
toolNameLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
toolNameLabel.setText(PFT.TOOL_NAME.getExplanationLabelText());
final Text toolNameText = new Text(mavniOptionsComposite, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
toolNameText.setLayoutData(textGridData);
widgetsMap.put(PFT.TOOL_NAME, toolNameText);
final Label toolVersionLabel = new Label(mavniOptionsComposite, SWT.NONE);
toolVersionLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
toolVersionLabel.setText(PFT.TOOL_VERSION.getExplanationLabelText());
final Text toolVersionText = new Text(mavniOptionsComposite, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
toolVersionText.setLayoutData(textGridData);
widgetsMap.put(PFT.TOOL_VERSION, toolVersionText);
mavniOptionsComposite.setLayout(new GridLayout(2, false));
new MavniOptionViewer(MyPreferences.getMavniOptionsList()).createViewer(mavniOptionsComposite);
createExpandItem(parent, mavniOptionsComposite, "Mavni Options", com.mavni.ui.Activator
.getDefault().getImageRegistry().get(IImageKeys.EXECUTE.getPath()), false);
但是我得到以下行为:
我希望表格扩展到完整布局。据我了解,发生这种情况是因为我设置了setLayout(new GridLayout(3, false));
并且该表仅包含两列。如果我设置了mavniOptionsComposite.setLayout(new GridLayout(2, false));
,则该表将按预期工作,但是其他元素在该位置未显示任何内容(就像现在应该显示的那样)。
通缉的行为:
起初,我虽然创建了两个GridLayouts并将它们插入到一个复合物中。我试图寻找一种将两种布局组合在一个复合物中的方法,但是找不到一种方法。我需要一个复合文件,因为createExpandItem
仅适用于一个复合文件。如何解决?
编辑:在MavniOptionViewer
中,我有:
public void createViewer(final Composite parent) {
commandsTable = new Table(parent, SWT.BORDER | SWT.FULL_SELECTION);
commandsTable.setHeaderVisible(true);
commandsTable.setLinesVisible(true);
final GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 5);
data.heightHint = 120;
commandsTable.setLayoutData(data);
final Map<ButtonTypeEnum, Button> buttons = ButtonComboFactory.createAddRemoveCombo(parent);
final Button add = buttons.get(ButtonTypeEnum.ADD);
final Button remove = buttons.get(ButtonTypeEnum.REMOVE);
...
尽管有其他可能的解决方案,是否可以更改createViewer
,所以表格将具有3列,并且add
remove
按钮将位于分隔行上。怎么做?
答案 0 :(得分:0)
复合材料只能具有一种布局,您不能将其更改一半。最终将使用您为所有内容设置的最后一个布局。
您可以在一个包含的Composite中使用多个Composite。
答案 1 :(得分:0)
您可以将主
Traceback (most recent call last):
File "C:\Users\matth\Desktop\MandRfraction.py", line 35, in <module>
f3 = f1+f2
File "C:\Users\matth\Desktop\MandRfraction.py", line 28, in __add__
common = gcd(newnum//common, newden//common)
NameError: name 'gcd' is not defined
保留为3列的Composite
,并告诉表格占据所有这3列,而不是像现在那样占据2列。
您可以通过将表GridLayout
的{{1}}从2更改为3来实现:
horizontal span
此外,您不应重复使用GridData
对象;来自documentation:
由
final GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 5);
管理的GridData
中的每个控件都必须具有 唯一的Composite
对象。