[英]How do I move a label to a new line?
Is there a new line command for SWT on windows? Windows上是否有用于SWT的新行命令? If there isn't, what am I doing wrong here? 如果没有,那我在做什么错?
Here's the code 这是代码
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;
}
} }
The problem is where I create a new Label under the //Grid3 comment. 问题是我在// Grid3注释下创建了一个新Label。 That label is sticking to the line above it, rather than coming to a new line. 该标签将粘贴在其上方的行上,而不是出现在新行上。 I'm brand new at SWT so I know it's just lack of knowledge on my part. 我是SWT的新手,所以我知道我只是缺乏知识。 I'll include a picture so you can see the issue. 我将附上一张图片,以便您看到问题所在。
You can see the label 'Todays Lines:' isn't on it's own line. 您可以看到标签“ Todays Lines:”不在其自己的行上。
Any help would be tremendously appreciated! 任何帮助将不胜感激!
You assign more than once the layout data of the Texts, first to new GridData()
then gridData2
. 您不止一次将文本的布局数据分配给new GridData()
然后gridData2
new GridData()
gridData2
。 Once is enough. 一次就够了。 The reason the new label does not appear on the new line is that the grid has 20 columns as set with gridLayout.numColumns = 20;
新标签未出现在新行上的原因是,网格具有20列,并通过gridLayout.numColumns = 20;
设置gridLayout.numColumns = 20;
. 。 gridData2
has horizontalSpan = 5
. gridData2
具有horizontalSpan = 5
。 If you add 3 labels (spanning 1 column as default) and three Texts spanning 5 columns (as per gridData2
), the label you want on the new line will appear in the 19th column still on the same row. 如果添加3个标签(默认情况下跨越1列)和3个Texts跨越5列(按照gridData2
),则您希望在新行上使用的标签将显示在第19列的同一行中。
I suggest to assign separate GridData
instances to the Texts and divide the number of columns to span among them to sum up to 20 (eg the last one spans not 5 but 7 columns), this way 'Today lines' will be placed in the next row. 我建议为文本分配单独的GridData
实例,并在其中划分列数以总计20(例如,最后一个跨度不是5而是7列),这样,“今日行”将放置在下一个行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.