Java SWT ScrolledForm背景颜色

时间:2015-04-24 17:27:07

标签: java background swt

我遇到ScrolledForm的问题。我正在尝试更改Label正文中定义的ScrolledForm的背景和前景颜色,但它似乎无法正常工作。

在我的代码段中,我希望lblWhat有黑色背景和白色前景。

这是我的代码段:

ScrolledForm scrldfrmNewScrolledform = formToolkit.createScrolledForm(parent);

scrldfrmNewScrolledform.setLayoutData(gd);

scrldfrmNewScrolledform.setFont(SWTResourceManager.getFont("Segoe UI", 16, SWT.NORMAL));
scrldfrmNewScrolledform.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND));
scrldfrmNewScrolledform.getBody().setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
scrldfrmNewScrolledform.setImage(SWTResourceManager.getImage(EPRForm.class, "/icons/AFCCEPR.png"));
scrldfrmNewScrolledform.setBounds(10, 10, 430, 280);
formToolkit.paintBordersFor(scrldfrmNewScrolledform);
scrldfrmNewScrolledform.setText("ePR (electronic Purchase Request)");

Label lblName = new Label(scrldfrmNewScrolledform.getBody(), SWT.NONE);
lblName.setBounds(10, 21, 55, 15);
formToolkit.adapt(lblName, true, true);
lblName.setText("Name:");

text = new Text(scrldfrmNewScrolledform.getBody(), SWT.BORDER);
text.setBounds(71, 15, 269, 21);
formToolkit.adapt(text, true, true);

Label lblWhat = new Label(scrldfrmNewScrolledform.getBody(), SWT.None);
lblWhat.setBounds(10, 35, 100, 15);
lblWhat.setBackground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
lblWhat.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
formToolkit.adapt(lblWhat, true, true);
lblWhat.setText("What do you want?");

Label lblItem = new Label(scrldfrmNewScrolledform.getBody(), SWT.None);
lblItem.setBounds(10, 55, 100, 15);
formToolkit.adapt(lblItem, true, true);
lblItem.setText("Items to be Ordered*");

txtItems = new Text(scrldfrmNewScrolledform.getBody(), SWT.BORDER | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL);
txtItems.setBounds(10, 60, 338, 84);
formToolkit.adapt(txtItems, true, true);

1 个答案:

答案 0 :(得分:1)

您似乎正在使用FormToolkitFormToolkit.adapt方法强制控件颜色为表单设置的颜色(通常为白色背景和黑色文本)。

对于单一控件,您可以在setBackground来电后尝试拨打setForegroundadapt

您可以使用

设置整个表单的颜色
FormColors colors = toolkit.getColors();

colors.setBackground(...);
colors.setForeground(...);