Bad text alignment for Label [message #720852] |
Wed, 31 August 2011 11:12 |
Alexey Romanov Messages: 263 Registered: May 2010 |
Senior Member |
|
|
Crosspost from Stack Overflow:
I am trying to do something that should be absolutely trivial, namely add a product version number to an RCP application's splash screen. So my code looks like this:
class ARMSplashHandler extends EclipseSplashHandler {
private Font font;
private int heightInPx = 12;
private int fontHeightInPt(Display display, int heightInPx) {
return 72 * heightInPx / display.getDPI().y;
}
@Override void init(Shell splash) {
Product product = Platform.getProduct();
Display display = splash.getDisplay();
FontData fontData = splash.getFont.getFontData()[0];
fontData.setHeight(fontHeightInPt(display, fontHeightInPx));
font = new Font(display, fontData);
splash.setBackgroundMode(SWT.INHERIT_DEFAULT);
splash.setText(product.getName());
splash.setFont(font);
String version = "v"+product.getDefiningBundle().getHeaders().get("Bundle-Version");
String versionLocString = product.getProperty("versionLocation");
String versionColorString = product.getProperty("versionColor");
Rectangle versionLoc = StringConverter.asRectangle(versionLocString, new Rectangle(405, 260, 45, 12));
Color versionColor = new Color(display, StringConverter.asRGB(versionColorString, new RGB(193, 202, 212)));
CLabel versionLabel = new CLabel(splash, SWT.CENTER | SWT.BORDER);
versionLabel.setForeground(versionColor);
versionLabel.setFont(font);
versionLabel.setBounds(versionLoc);
versionLabel.setText(version);
splash.addDisposeListener(new DisposeListener {
void widgetDisposed(DisposeEvent e) {
versionColor.dispose();
font.dispose();
}
});
super.init(splash);
}
This works fine (except for a problem on Mac I'll ask about in a separate question; of course, the border is just for debugging):
But if I replace `CLabel` with `Label`, this happens:
It isn't centered, as expected. If I set alignment to `RIGHT` (which is what I really want), it disappears completely. Initially I thought the problem simply was that there isn't enough space, but increasing height of the rectangle only fixes vertical centering, and the width is certainly large enough:
Is this somehow expected behavior? Or an SWT bug (I certainly don't expect there to be one in something this basic)?
[Updated on: Wed, 31 August 2011 11:12] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02527 seconds