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);
        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):
http://i.stack.imgur.com/pgCbm.png
But if I replace `CLabel` with `Label`, this happens:
http://i.stack.imgur.com/ISiWr.png
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:
http://i.stack.imgur.com/lAYuY.png
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: Tue Dec 23 00:55:28 GMT 2014

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

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