我是SWT和java的新手 我真的需要帮助。
我需要构建Eclipse插件,当你按下按钮时应该打开一个对话框。
对话框应该看起来像
label 1 textBox1 label 2 textBox 2
label 3 textBox13 label 4 textBox 4
could be alot of them -> should be with scroller
---------------------------------------------------
output ( should be textbox)
-----------------------------------------------------
messages ( should be textbox)
它可能有很多标签和文本框,我如何将它们添加到可以容纳很多它们的控件中? (应该使用滚动条)
如何在SWT或fjace中将屏幕拆分为3个部分?以及如何控制大小,例如第一部分(标签文本框)将为60%,输出为30%,消息为10%?
也许你可以帮我举个例子吗?
答案 0 :(得分:2)
这需要太多的代码 - 你应该向我们展示你尝试过的东西!
一些提示:
使用org.eclipse.jface.dialog.Dialog
作为对话框,您还可以使用org.eclipse.jface.dialog.TitleAreaDialog
,其中包含错误消息区域。
要按百分比拆分区域,请使用org.eclipse.swt.custom.SashForm
。
要在一行中获取多个项目,请使用org.eclipse.swt.layout.GridLayout
指定列数。
要获得滚动区域,请使用org.eclipse.swt.custom.ScrolledComposite
类似于:
@Override
protected Control createDialogArea(final Composite parent)
{
Composite body = (Composite)super.createDialogArea(parent);
// Vertical sash
SashForm sashForm = new SashForm(body, SWT.VERTICAL);
sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
// First part, scrollable
ScrolledComposite scrolledComp = new ScrolledComposite(sashForm, SWT.V_SCROLL);
Composite comp1 = new Composite(scrolledComp, SWT.NONE);
comp1.setLayout(new GridLayout());
// TODO: add controls to comp1
// Set scroll size - may need to adjust this
Point size = comp1.computeSize(SWT.DEFAULT, SWT.DEFAULT);
scrolledComp.setMinHeight(size.y);
scrolledComp.setMinWidth(size.x);
scrolledComp.setExpandVertical(true);
scrolledComp.setExpandHorizontal(true);
scrolledComp.setContent(comp1);
// Second part
Composite comp2 = new Composite(sashForm, SWT.NONE);
comp2.setLayout(new GridLayout());
// TODO: add controls to comp2
// Third part
Composite comp3 = new Composite(sashForm, SWT.NONE);
comp3.setLayout(new GridLayout());
// TODO: add controls to comp3
// Set the sash weighting (must be after controls are created)
sashForm.setWeights(new int [] {60, 30, 10});
return body;
}