Java SWT:真实分离器太高;横向太短;桌子太窄了
我是一个SWT新手,我很难让我的UI看起来像我想要的那样。考虑下面的代码,从SWT片段中拼凑起来:Java SWT:真实分离器太高;横向太短;桌子太窄了,java,user-interface,swt,Java,User Interface,Swt,我是一个SWT新手,我很难让我的UI看起来像我想要的那样。考虑下面的代码,从SWT片段中拼凑起来: Display.setAppName("App Name"); Display display = new Display(); Shell shell = new Shell(display); GridLayout shellLayout = new GridLayout(); shellLayout.numColumns = 1; shel
Display.setAppName("App Name");
Display display = new Display();
Shell shell = new Shell(display);
GridLayout shellLayout = new GridLayout();
shellLayout.numColumns = 1;
shell.setLayout(shellLayout);
Group group = new Group(shell, SWT.DEFAULT);
RowLayout groupLayout = new RowLayout();
group.setLayout(groupLayout);
for (int i = 0; i < 3; i++)
new Button(group, SWT.PUSH).setText("ABC" + i);
new Label(group, SWT.SEPARATOR | SWT.VERTICAL);
for (int i = 0; i < 3; i++)
new Button(group, SWT.PUSH).setText("ABC" + i);
new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
Table table = new Table(shell, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
table.setLinesVisible(true);
table.setHeaderVisible(true);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
table.setLayoutData(gridData);
for (String title : new String[] { "A", "B", "C", "D", "E", "F", "G" })
new TableColumn(table, SWT.NONE).setText(title);
for (int i = 0; i < 128; i++) {
TableItem item = new TableItem (table, SWT.NONE);
item.setText(0, "123");
item.setText(1, "234");
item.setText(2, "345");
item.setText(3, "456");
item.setText(4, "567");
item.setText(5, "678");
item.setText(6, "789");
}
for (TableColumn column : table.getColumns())
column.pack();
shell.pack();
shell.open();
while (shell.isDisposed() != true)
if (display.readAndDispatch() != true)
display.sleep();
display.dispose();
Display.setAppName(“应用程序名称”);
显示=新显示();
外壳=新外壳(显示);
GridLayout shellLayout=新的GridLayout();
shellLayout.numColumns=1;
shell.setLayout(shell布局);
组组=新组(shell,SWT.DEFAULT);
RowLayout groupLayout=新建RowLayout();
group.setLayout(groupLayout);
对于(int i=0;i<3;i++)
新按钮(组,SWT.PUSH).SETEXT(“ABC”+i);
新标签(组,SWT.SEPARATOR | SWT.VERTICAL);
对于(int i=0;i<3;i++)
新按钮(组,SWT.PUSH).SETEXT(“ABC”+i);
新标签(外壳、SWT分离器| SWT水平);
Table Table=新表格(shell、SWT.MULTI | SWT.BORDER | SWT.FULL|u选择);
表.setLinesVisible(真);
表.setheadervible(true);
GridData GridData=新的GridData(SWT.FILL,SWT.FILL,true,true);
表.setLayoutData(gridData);
for(字符串标题:新字符串[]{“A”、“B”、“C”、“D”、“E”、“F”、“G”})
新的TableColumn(table,SWT.NONE).setText(title);
对于(int i=0;i<128;i++){
TableItem项目=新的TableItem(表,SWT.NONE);
第条第(0,“123”)款;
第条第(1,“234”)款;
项目.第(2,“345”)款;
第2项第(3,“456”)款;
第2项第(4,“567”)款;
第6项第(5,“678”)款;
第6项,“789”);
}
for(TableColumn列:table.getColumns())
column.pack();
shell.pack();
shell.open();
while(shell.isDisposed()!=true)
if(display.readAndDispatch()!=true)
display.sleep();
display.dispose();
运行时,结果显示有以下问题:
水平标签需要被告知要占据更多的空间
Label temp = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
temp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
对column.pack()的调用改变列宽以匹配数据。如果要将它们设置为显式大小,则需要在列对象上实际设置属性,而不仅仅是使用新列创建属性。要使所有列随窗口和表动态调整大小,需要为表编写ResizeListener。否则,无论表格大小如何,列都会保持不变。需要告诉水平标签获取更多空间
Label temp = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
temp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
对column.pack()的调用改变列宽以匹配数据。如果要将它们设置为显式大小,则需要在列对象上实际设置属性,而不仅仅是使用新列创建属性。要使所有列随窗口和表动态调整大小,需要为表编写ResizeListener。否则,无论表格大小如何,列都会保持不变。可以使用布局数据设置垂直分隔符的高度
Button button = null;
for (int i = 0; i < 3; i++) {
button = new Button(group, SWT.PUSH);
button.setText("ABC" + i);
}
Label verticalSeparator = new Label(group, SWT.SEPARATOR | SWT.VERTICAL);
RowData layoutData = new RowData();
layoutData.height = button.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
verticalSeparator.setLayoutData(layoutData);
按钮=null;
对于(int i=0;i<3;i++){
按钮=新按钮(组,SWT.按钮);
按钮设置文本(“ABC”+i);
}
标签垂直分隔符=新标签(组,SWT.SEPARATOR | SWT.VERTICAL);
RowData layoutData=新的RowData();
layoutData.height=button.computeSize(SWT.DEFAULT,SWT.DEFAULT).y;
垂直分隔符。setLayoutData(layoutData);
可以使用布局数据设置垂直分隔符的高度
Button button = null;
for (int i = 0; i < 3; i++) {
button = new Button(group, SWT.PUSH);
button.setText("ABC" + i);
}
Label verticalSeparator = new Label(group, SWT.SEPARATOR | SWT.VERTICAL);
RowData layoutData = new RowData();
layoutData.height = button.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
verticalSeparator.setLayoutData(layoutData);
按钮=null;
对于(int i=0;i<3;i++){
按钮=新按钮(组,SWT.按钮);
按钮设置文本(“ABC”+i);
}
标签垂直分隔符=新标签(组,SWT.SEPARATOR | SWT.VERTICAL);
RowData layoutData=新的RowData();
layoutData.height=button.computeSize(SWT.DEFAULT,SWT.DEFAULT).y;
垂直分隔符。setLayoutData(layoutData);
用于固定水平分隔符。关于如何使垂直标签仅与按钮一样高,有什么想法吗?目前它的高度是原来的两倍。这就修复了水平分隔线。关于如何使垂直标签仅与按钮一样高,有什么想法吗?目前它的高度是原来的两倍。