1

Can the width of the tab-header of a CTabItem be set arbitrary?

Thnx in advance!

Kind regard, Marcus

Marcus Toepper
  • 2,403
  • 4
  • 27
  • 42

3 Answers3

2

You can try to override CTabItem, but this solution doesn't look as nice solution (nevertheless I use it):

CTabItem tabItem;

final int tabWidth = 90;

tabItem = new CTabItem( tabFolder, SWT.NONE ) {
    @Override
    public Rectangle getBounds( ) {
        Rectangle bounds = super.getBounds();
        bounds.x = 0 * tabWidth;
        bounds.width = tabWidth;
        return bounds;
    }
};
tabItem.setText( __lang.str( this, "Tab Item I" ) );

tabItem = new CTabItem( tabFolder, SWT.NONE ) {
    @Override
    public Rectangle getBounds( ) {
        Rectangle bounds = super.getBounds();
        bounds.x = 1 * tabWidth;
        bounds.width = tabWidth;
        return bounds;
    }
};
tabItem.setText( __lang.str( this, "Tab Item II" ) );

tabItem = new CTabItem( tabFolder, SWT.NONE ) {
    @Override
    public Rectangle getBounds( ) {
        Rectangle bounds = super.getBounds();
        bounds.x = 2 * tabWidth;
        bounds.width = tabWidth;
        return bounds;
    }
};
tabItem.setText( __lang.str( this, "Tab Item III" ) );
Nicolai
  • 5,489
  • 1
  • 24
  • 31
  • I like this. I also used `tabFolder.indexOf(this)` inside the `getBounds()` method to get the correct x offset. – Campa Oct 01 '19 at 15:14
0

As a workaround, you can pad the title with extra spaces using String.format like:

cTabItem.setText(String.format("%-15s", orgTitle));

This will add extra spaces to the end of the string if its length is less than 15 characters.

Check this for more details: https://docs.oracle.com/javase/tutorial/essential/io/formatting.html

TENNO
  • 165
  • 2
  • 11
0

No you can't do that. Not at least by any exposed API (read public methods). A possible solution is to extend the code of CTabFolder and CTabItem.

Favonius
  • 13,959
  • 3
  • 55
  • 95