Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Bad text alignment for Label
Bad text alignment for Label [message #720852] Wed, 31 August 2011 11:12
Alexey Romanov is currently offline Alexey RomanovFriend
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);
        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);
        splash.addDisposeListener(new DisposeListener {
          void widgetDisposed(DisposeEvent e) { 

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

Previous Topic:Can't commit in Git because of XPCOM error -2147467262
Next Topic:Why is there a limit on no of widgets, based on no of handles?
Goto Forum:

Current Time: Sun Jan 17 17:33:15 GMT 2021

Powered by FUDForum. Page generated in 0.02341 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top