我怎样才能有一个可滚动的禁用文本?

我的文字声明为,

Text text= new Text(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.WRAP); 

在某些情况下应该禁用它。 但是,当我这样做
text.setEnabled(假); 文本的滚动条也被禁用,我无法完全看到文本中的值。

我的文本字段不能只读。 在某些情况下它应该是可编辑的。

我知道Text中的setEditable()方法,但我希望具有与禁用文本时相同的行为,即背景颜色更改,没有闪烁的光标(插入符号),无法执行鼠标单击以及文本无法选择等等

通过这样做,我能够改变背景颜色

 text.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); 

但我无法禁用光标,文本选择和鼠标单击。

在此处输入图像描述

有没有办法让滚动条对禁用的文本保持活动状态?

禁用时,您将无法使Text控件显示滚动条。 它只是本机控件的工作方式,即操作系统呈现控件的方式。

但是 ,您可以将Text包装在ScrolledComposite 。 这样, ScrolledComposite将滚动而不是Text

这是一个例子:

 public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout(SWT.VERTICAL)); final ScrolledComposite composite = new ScrolledComposite(shell, SWT.V_SCROLL); composite.setLayout(new FillLayout()); final Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP); composite.setContent(text); composite.setExpandHorizontal(true); composite.setExpandVertical(true); composite.setMinSize(text.computeSize(SWT.DEFAULT, SWT.DEFAULT)); Button button = new Button(shell, SWT.PUSH); button.setText("Add text and disable"); button.addListener(SWT.Selection, new Listener() { @Override public void handleEvent(Event arg0) { text.setText("lalala\nlalala\nlalala\nlalala\nlalala\nlalala\n"); text.setEnabled(false); composite.setMinSize(text.computeSize(SWT.DEFAULT, SWT.DEFAULT)); } }); shell.pack(); shell.setSize(300, 150); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } 

这就是它的样子:

在此处输入图像描述