How to correctly style borders of a CTabItem

こ雲淡風輕ζ 提交于 2019-12-05 02:28:22

问题


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?


回答1:


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

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


来源:https://stackoverflow.com/questions/6649756/how-to-correctly-style-borders-of-a-ctabitem

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!