如何正确设置CTabItem的边框 [英] How to correctly style borders of a CTabItem

查看:147
本文介绍了如何正确设置CTabItem的边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个Eclipse插件,它提供了一些使用CTabFolder组件的UI。





Eclipse提供的CTabItem在活动时有一个蓝色边框,当不活动时为白色边框(如果CTabItem为一个Eclipse视图)。



我创建的CTabItems始终是白色的,活动选项卡上的文本被加下划线。



如何控制我的CTabItems的样式更紧密地匹配Eclipse选项卡?



编辑:



我已经提出了从活动Eclipse主题中提取正确颜色的以下代码。

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

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

然而,这不是理想的,因为IWorkbenchThemeConstants在eclipse ui内部包中。



是否有一种替代的公共方式来引用这些内部IWorkbenchThemeConstants引用的相同颜色?

解决方案

您可以使用方法来定义选定和未选择的CTabFolder项目的渐变。例如

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

会产生这个(丑陋的)标签





所以你只需要你可以编写你自己的 CTabFolderRenderer 并将其设置为您的CTabFolder实例。 p>

编辑



对于Eclipse颜色尝试

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



编辑



如何正确执行

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


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

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

这篇关于如何正确设置CTabItem的边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆