Marcus Toepper
Marcus Toepper

Reputation: 2433

Set header-width of CTabItem

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

Thnx in advance!

Kind regard, Marcus

Upvotes: 1

Views: 788

Answers (3)

TENNO
TENNO

Reputation: 165

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

Upvotes: 0

Nicolai
Nicolai

Reputation: 5797

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" ) );

Upvotes: 2

Favonius
Favonius

Reputation: 13974

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.

Upvotes: 0

Related Questions