You won't be able to make the Text
control show scrollbars when it'd disabled. It's just the way the native control works, i.e., the way the OS renders the controls.
However, you can wrap your Text
in a ScrolledComposite
. That way, the ScrolledComposite
will scroll instead of the Text
.
Here is an example:
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();
}
This is what it looks like: