简体   繁体   中英

How to correctly style borders of a CTabItem

I have written an Eclipse plugin which provides some UI which uses the CTabFolder component.

应用截图

The CTabItems provided by Eclipse have a blue border when active and a white border when inactive (grey if the CTabItem is an Eclipse View).

The CTabItems which I have created are always bordered in white and the text on the active tab is underlined.

How can I control the style of my CTabItems to more closely match the Eclipse tabs?

EDIT:

I have come up with the following code which extracts the correct colors from the active Eclipse theme.

IWorkbench workBench = PlatformUI.getWorkbench();
ITheme theme = workBench.getThemeManager().getCurrentTheme();
ColorRegistry colreg = theme.getColorRegistry();

Color c1 = colreg.get(IWorkbenchThemeConstants.ACTIVE_TAB_BG_START);
Color c2 = colreg.get(IWorkbenchThemeConstants.ACTIVE_TAB_BG_END);

However, this isn't ideal as IWorkbenchThemeConstants is within an eclipse ui internal package.

Is there an alternative public way to reference the same colors referred to by these internal IWorkbenchThemeConstants?

You can use methods for defining gradient on selected and non-selected CTabFolder items. For example

CTabFolder folder = new CTabFolder(shell, SWT.BORDER);
folder.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_YELLOW), display.getSystemColor(SWT.COLOR_RED)}, new int[]{100}, true);
folder.setSelectionBackground(new Color[]{display.getSystemColor(SWT.COLOR_WHITE), display.getSystemColor(SWT.COLOR_BLUE)}, new int[]{100}, true);

will produces this (ugly) tabs

彩色 SWT CTabFolder

So you just have to hit right colors which eclipse have..

Or you could write your own CTabFolderRenderer and set it to your CTabFolder instance.

EDIT

For Eclipse colors try

folder.setSelectionBackground(new Color[]{new Color(display, new RGB(242, 244, 247)), new Color(display, new RGB(157, 167, 195))}, new int[]{100}, true);

在此处输入图像描述

EDIT

Found the way how to do it correctly

folder.setSelectionBackground(new Color[]{display.getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT), display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND)}, new int[]{100}, true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM