- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个方法可以创建 2 个按钮。这些按钮不同于确定、关闭按钮。单击时它们将执行不同的操作。我希望 2 个按钮并排放置在我的基本组合的顶部。这是使用 GridLayout。我希望能够并排放置按钮。
这是我要添加方法的 createDialogArea。
protected Control createDialogArea(Composite parent) {
final Composite area = new Composite(parent, SWT.NONE);
final GridLayout gridLayout = new GridLayout();
gridLayout.marginWidth = 15;
gridLayout.marginHeight = 10;
area.setLayout(gridLayout);
createTopButtons(area);
createTableViewer(area);
return area;
}
这里是按钮方法。
protected void createTopButtons(Composite parent) {
Button pdfButton = new Button(parent, SWT.PUSH);
pdfButton.setText("Create PDF");
pdfButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
close();
}
});
Button plotButton = new Button(parent, SWT.PUSH);
plotButton.setText("Plot");
plotButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
close();
}
});
}
我需要为 createTopButtons 添加一个 Gridlayout 吗?
如果是这样,我如何将它们并排放置而不是一个放在另一个之上。
同样在 createDialogArea 中,我可以使用 gridLayout 排列我的组件吗?
示例 - 我希望 createTopButtons 位于左上角,然后我希望 createTableViewer 居中
您是否使用正在创建的复合内部的布局(如 createTopButtons)来安排项目/按钮/标签。然后在 createDialogArea 中使用布局来排列方法创建的组合?
最佳答案
Would I need to add a Gridlayout to createTopButtons?
不,您需要将按钮放在另一个组合中,这个子组合应该有一个包含两列的网格布局。
Also in the createDialogArea, can I arrange my components using the gridLayout? Example - I want createTopButtons to be on the top left hand side, then I want createTableViewer centered
当然,为什么不呢。但是您还需要一个名为 GridData
的东西,并将其设置为 area.setLayoutData(gridData);
。为了使某物居中,您的网格数据可能如下所示 gridData = new GridData(SWT.CENTER, SWT.CENTER, true, false);
Do you arrange your items/buttons/labels using a layout inside the composite you are creating like createTopButtons. Then use a layout in the createDialogArea to arrange the composite created by the methods?
是的。尽管我无法得到后半部分 由方法创建的复合 Material
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
public class SideBySide {
public static void main(String[] args) {
new SideBySide().start();
}
private Shell shell;
public void start()
{
Display display = new Display();
shell = new Shell(display);
shell.setLayout(new GridLayout(1, true));
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
shell.setLayoutData(gridData);
shell.setText("Side By Side");
createDialogArea(shell);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
protected Control createDialogArea(Composite parent)
{
final Composite area = new Composite(parent, SWT.NONE);
final GridLayout gridLayout = new GridLayout();
gridLayout.marginWidth = 15;
gridLayout.marginHeight = 10;
area.setLayout(gridLayout);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
shell.setLayoutData(gridData);
area.setLayoutData(gridData);
createTopButtons(area);
createTableViewer(area);
return area;
}
private void createTableViewer(Composite area)
{
Table table = new Table(area, SWT.BORDER|SWT.V_SCROLL|SWT.FULL_SELECTION);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
table.setLayoutData(gridData);
table.setLinesVisible(true);
table.setHeaderVisible(true);
TableColumn column = new TableColumn(table, SWT.LEFT);
column.setWidth(320);
column.setText("Column 1");
column = new TableColumn(table, SWT.LEFT);
column.setWidth(320);
column.setText("Column 2");
}
protected void createTopButtons(Composite parent)
{
Composite composite = new Composite(parent, SWT.NONE);
GridLayout gridLayout = new GridLayout(2, false);
gridLayout.marginWidth = 0;
gridLayout.marginHeight = 0;
gridLayout.verticalSpacing = 0;
gridLayout.horizontalSpacing = 0;
composite.setLayout(gridLayout);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
composite.setLayoutData(gridData);
gridData = new GridData(SWT.DEFAULT, SWT.FILL, false, false);
Button pdfButton = new Button(composite, SWT.PUSH);
pdfButton.setText("Create PDF");
pdfButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
shell.close();
}
});
pdfButton.setLayoutData(gridData);
Button plotButton = new Button(composite, SWT.PUSH);
plotButton.setText("Plot");
plotButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
shell.close();
}
});
plotButton.setLayoutData(gridData);
}
}
这是一个 great article了解 SWT 中的布局。
关于java - SWT - GridData 和按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12170017/
我实际上是在尝试在 Java SWT 中重现类似的东西,但到目前为止还没有成功: 我看到的问题是,据我所知,SWT.TITLE 需要显示 SWT.CLOSE、SWT.MAX 和 SWT.MIN 谁能告
以下是我的代码: Group leftGroup = new Group(parent, SWT.NONE); leftListWidget = new org.eclipse.swt.widgets
我正在尝试运行一个 hello world SWT 应用程序: public static void main(String args[]) throws IOException{ Displ
我有一个 SWT 窗口,其中有组小部件,我在其中放置了几个其他小部件,我设置了组的标题及其工作正常。组标题颜色始终为蓝色(在我的情况下我不确定)并且不会与组内的其他 child 同步。所以我想知道是否
我正在使用 SWT CTabFolder 在我的应用程序中构建选项卡。我有点不喜欢标签的视觉外观,它太像 Eclipse。有没有办法改变标签的方面?我想更改关闭按钮,例如标签的位置,它们的外观可能..
对于我在使用大型 SWT 表的 RCP 应用程序中追逐了一段时间的问题,这更多是我想分享的答案。 问题是 SWT Table.remove(int start, int end) 方法的性能。它提供了
如何在不使用鼠标监听器的情况下编辑 SWT 表值? 最佳答案 做 TableEditor以下链接中的片段有帮助吗? SWT Snippets TableEditor中的第一个例子部分使用 Select
我想要一个带有两行工具提示的控件。例如 Label: Label label = new Label( parent, SWT.NONE ); label.setText( "label text"
A 想在我的 View 上加载下拉菜单时添加默认文本。我怎样才能在 SWT 和 JFace 中做到这一点? 最佳答案 我猜您想要做的是在将某些内容添加到 View 时在组合中显示某些内容(默认情况下它
在我的登录对话框中,有一个按钮: Text pwdT = new Text(container, SWT.BORDER|SWT.PASSWORD); Button plainBtn = new Bu
如何以编程方式垂直滚动 SWT 表? 在表上实现搜索功能。当找到一个项目时,它将滚动到找到的项目。 最佳答案 您可能想尝试几种方法: Table.showItem(TableItem) Table.s
我有一个 Composite我希望能够以编程方式启用/禁用。 Control.setEnabled(boolean enabled)方法工作正常,但它没有提供任何小部件被禁用的视觉信息。 我想做的是让
有几个“高级”表格/电子表格 SWT 小部件(Nattable、Nebula Grid),但它们都不支持真正的大数据集。 Nattable 是最接近的一种,但它在使用的数据类型方面仍然存在限制,导致表
以下问题让我感到困惑:我有一个 SWT Java 应用程序,并且在以下情况下从 SWT 3 切换到 SWT 4 会导致 KeyDown 事件出现奇怪的行为: 我有一个包含浏览器小部件的外壳。我正在通过
我在 eclipse SWT 应用程序中有许多表。它们是 Table/TableViewer 表格,由一个标题、左下方一行文本和一系列图形组成。除文本列外还有 32 列,编号从 0 到 31。在经典模
原目标: 我有一个 TreeMenu 用于显示我的菜单。 在这棵树中,用户可以选择不同的项目。 我想禁用树,以便用户在选择第一个项目后无法选择新项目。 问题是,我们不能使用 setEnabled,因为
是否已经有人在 IDEA 中编写了类似于“导航栏”的 SWT 控件?对于那些不知道我的意思的人:它看起来像 path1 > path2 > path3 > 其中每个“路径”都是模拟一个按钮的完整路径的
我需要使用 SWT/JFace 实现多选组合框,最好的方法是什么?我应该更改源代码还是应该尝试扩展组合? 最佳答案 不可能扩展 Combo 可以通过重写 checkSubclass() 来扩展 Com
我想用大量行(最多 3 mio)填充 SWT 虚拟表。当我使用懒惰的内容提供者时,我不能使用过滤器,而当我使用普通的内容提供者时,更改过滤器的性能会变得非常糟糕。有没有办法在 SWT 或 JFace
除了外观之外,组控制和复合之间有什么区别?我可以将容器放入组内吗?如果是,我必须使用什么布局?我尝试将容器放置在组内,但容器内的控件未显示。 Group grp= new Group(containe
我是一名优秀的程序员,十分优秀!