本文介绍了JFace PopupDialog 中小部件的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 JFace PopupDialog 用作用户输入的轻量级对话框.但是我对文本小部件的背景颜色有一些问题.

I want to use the JFace PopupDialog as lightweight dialog for user input. But I have some problems with the background color of text widgets.

正如您在下面的 1 中看到的,SWT.MULTI 文本小部件具有没有背景和边框,SWT.SINGLE 文本小部件没有背景.我试图用以下方法覆盖背景颜色:

As you can see below in 1, a SWT.MULTI text widget has no background and border, a SWT.SINGLE text widget has no background.I tried to override the background color with:

Text comment = new Text(composite, SWT.MULTI|SWT.BORDER);
comment.setFocus();
comment.setBackground(new Color(Display.getDefault(), new RGB(000, 000, 000)));
// method of PopupDialog
applyBackgroundColor(new Color(Display.getDefault(), new RGB(000, 000, 000)), comment);

有人知道如何正确处理这个问题吗?

Does anybody has any idea how to handle this properly?

提前致谢!

更新:尝试覆盖 PopupDialog 的方法 getBackground() 并让它返回你想要的颜色.您的代码可能在 createDialogArea(..) 中,并且 PopupDialog 将这种颜色应用于您的代码之后 的所有内容.如果您只想更改特定控件的背景颜色,您可以尝试以下操作:

Update:Try to override the method getBackground() of PopupDialog and let it return the color you want. Your code probably is in createDialogArea(..) and PopupDialog applies this color to basically everything after your code.If you only want to change the background color of specific controls, you could try the following:

@Override
protected Control createContents(Composite parent) {
  Composite contents = super.createContents(parent);

  // set the color here

  return contents;
}

这篇关于JFace PopupDialog 中小部件的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-21 19:13