Windows上有SWT的新行命令吗?如果没有,我在这里做错了什么?
这是代码
public static void main (String [] args) {
Display display = new Display();
Shell shell = new TabsTest().createShell(display);
shell.setSize(350,500);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
private Shell createShell(final Display display) {
final Shell shell = new Shell(display);
shell.setText("Betting Tracker");
//Creating grid layout, used to organize the shell
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 20;
shell.setLayout(gridLayout);
//Grid1
GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
gridData.horizontalSpan = 20;
new Label(shell, SWT.NONE).setText("Bet Type:");
betType = new Combo(shell, SWT.SINGLE | SWT.BORDER);
betType.setItems(new String[] {" ", "NFL", "NBA", "CFB"});
betType.setLayoutData(gridData);
//Grid2
GridData gridData2 = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
gridData2.widthHint = 20;
gridData2.horizontalSpan = 5;
new Label(shell, SWT.NONE).setText("Bets Played:");
numBets = new Text(shell, SWT.NONE);
numBets.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
numBets.setLayoutData(gridData2);
new Label(shell, SWT.NONE).setText(" Won: ");
betsWon = new Text(shell, SWT.NONE);
betsWon.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
betsWon.setLayoutData(gridData2);
new Label(shell, SWT.NONE).setText(" Lost: ");
betsWon = new Text(shell, SWT.FILL);
betsWon.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true));
betsWon.setLayoutData(gridData2);
//Grid3
GridData gridData3 = new GridData(GridData.CENTER, GridData.CENTER, true, false);
gridData3.horizontalSpan = 20;
new Label(shell, SWT.NONE).setText("Todays Lines");
lines = new List(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
lines.setItems(new String[] { "OKC(+2.5) - MIA(-2.5)", "DAL(+8) - BOS(-8)" });
int listHeight = lines.getItemHeight() * 12;
trim = lines.computeTrim(0, 0, 0, listHeight);
gridData3.heightHint = trim.height;
lines.setLayoutData(gridData3);
return shell;
}
}
问题是我在// Grid3注释下创建一个新Label。那个标签贴在它上面的线上,而不是走向一条新线。我在SWT是全新的,所以我知道这只是我缺乏知识。我会包含一张图片,以便您查看问题。
你可以看到标签'Todays Lines:'不在它自己的行上。
非常感谢任何帮助!
答案 0 :(得分:4)
您不止一次分配文本的布局数据,首先分配到new GridData()
然后gridData2
。一次就够了。
新标签未出现在新行上的原因是网格有20列,其中gridLayout.numColumns = 20;
设置。 gridData2
有horizontalSpan = 5
。如果添加3个标签(默认为1列)和3个跨越5列的文本(根据gridData2
),则新行上所需的标签将显示在同一行的第19列中。
我建议为文本分配单独的GridData
个实例,并将列数除以它们之间的总数达20(例如最后一个不跨5但是7列),这样'今天行'将被放置在下一行。