I have to display the content of a file using some widgets of Eclipse SWT. The file has structure, it has unkown number of rows with unknown number of columns. The file is formatted properly (i.e. the second column in the first row starts exactly where the second column of the second, third, etc... row.) It has a table-like structure without having an actual table:
itt.van.juci tt.mm.yyyy // hh:mm:ss
juci 14.09.2017 // 08;08:08
If a read the file and print it again to another file I get the same structure without any distortion.
However if I read it into String and use this String to set an SWT Label or SWT.Text I get distorted appearance. The rows in the second (and any subsequent columns) do not start at the same place. The length of the content of the first column influences the starting point of the later columns:
itt.van.juci tt.mm.yyyy // hh:mm:ss
juci 14.09.2017 // 08;08:08
Is there a way to get rid of these extra spaces and keep the original structure?
Here is the setting-the-label part that I use:
Label historyLabel = new Label(compositeFiles, SWT.WRAP);
GridData gd_lblNewLabel = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
gd_lblNewLabel.widthHint = 566;
gd_lblNewLabel.heightHint = 237;
historyLabel.setLayoutData(gd_lblNewLabel);
historyLabel.setText(Dummy.dummyHistory());
}
and here is reading the file:
private static String java_8() {
StringBuilder sb = new StringBuilder();
try (Stream<String> stream = Files.lines(Paths.get(fileName_2))) {
stream.forEach(line->{
sb.append(line).append("\n");
});
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
Any solution is highly appreciated. I do not need to use org.eclipse.swt.widgets.Text
if other widgets suit more. However it would be difficult to use a Table since I do not know how many columns I need.
I need to set the font like this:
Font mono = new Font(compositeFiles.getDisplay(), "Courier New", 12, SWT.NONE);
historyLabel.setFont(mono);
My answare is based on the hints given by greg-449.