Senyokbalgul
Senyokbalgul

Reputation: 1102

How to disable listbox horizontal scrolling in Matlab GUI

When a string or sentence becomes too long, the horizontal scrolling of the Matlab GUIDE listbox component is activated. How can I disable this feature and allow the long string or sentence to continue on the next line?

Upvotes: 0

Views: 478

Answers (1)

Stewie Griffin
Stewie Griffin

Reputation: 14939

I misunderstood the question, so my answer was not correct (but it was accepted).

What you want can be achieved, but it's not documented. Check out Undocumented features, to see more information.

From the link:

Line-wrapping

By default, line-wrapping is turned on, effectively disabling horizontal scrolling (which is why Matlab set the HorizontalScrollBarPolicy to HORIZONTAL_SCROLLBAR_NEVER. However, in some cases it may be more useful to turn line-wrapping off and horizontal scrolling on using the TextArea’s setWrapping() method. Here’s a usage example:

jViewPort = jScrollPane.getViewport; jEditbox =
jViewPort.getComponent(0); jEditbox.setWrapping(false);  % do *NOT*
use set(...)!!! newPolicy =
jScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED;
set(jScrollPane,'HorizontalScrollBarPolicy',newPolicy);

Also, check this link: this link:

If you want it to appear like it's on separate lines, but let Matlab parse it like it's on a single line then you will have to use another editor. I don't think there are any editors with built-in syntax highlighting that supports this, so your best bet is probably something like MS Word with fixed-size font (Courier New or something). A horrible horrible idea, in my opinion, but it's possible.

The "correct" way to do this is to use ... to create multi-line strings / assignments etc:

Examples:

mystring = ['Accelerating the pace of ' ... 
        'engineering and science'];

or with equations:

s = 1 - 1/2 + 1/3 - 1/4 + 1/5 ...
      - 1/6 + 1/7 - 1/8 + 1/9;

Upvotes: 1

Related Questions