Reputation: 5044
Is there a new line command for SWT on windows? 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. 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. 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.
Any help would be tremendously appreciated!
Upvotes: 0
Views: 2156
Reputation: 1001
You assign more than once the layout data of the Texts, first to new GridData()
then 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;
. gridData2
has 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.
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 (e.g. the last one spans not 5 but 7 columns), this way 'Today lines' will be placed in the next row.
Upvotes: 4