Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Alignment of strings

Subject: Alignment of strings

From: jens

Date: 22 May, 2010 10:11:07

Message: 1 of 5

Hi All

I want to align some strings in a GUI. I have the following example:


           h={'Product Name' 'Price' 'Code'}
           j={'Newcastle' '20' 'EU20'}
          bongo=[h ;j]
          
set(h,'string',sprintf('%s %s\n',bongo{:}))% h is a handle to a text box.
           

I want the left column to be vertical aligned. Both h and j har cellarrays which contains many numbers and characters. Maybe I could make some code that extend the strings in the left column if the length of the strings are different?

Best Regards

Jens

Subject: Alignment of strings

From: jens

Date: 23 May, 2010 15:28:03

Message: 2 of 5

"jens " <pascal@hotmail.com> wrote in message <ht8ajr$sfr$1@fred.mathworks.com>...
> Hi All
>
> I want to align some strings in a GUI. I have the following example:
>
>
> h={'Product Name' 'Price' 'Code'}
> j={'Newcastle' '20' 'EU20'}
> bongo=[h ;j]
>
> set(h,'string',sprintf('%s %s\n',bongo{:}))% h is a handle to a text box.
>
>
> I want the left column to be vertical aligned. Both h and j har cellarrays which contains many numbers and characters. Maybe I could make some code that extend the strings in the left column if the length of the strings are different?
>
> Best Regards
>
> Jens

Hi

Does anybody know how to fix my problem?

/jens

Subject: Alignment of strings

From: Walter Roberson

Date: 23 May, 2010 15:37:14

Message: 3 of 5

jens wrote:
> "jens " <pascal@hotmail.com> wrote in message
> <ht8ajr$sfr$1@fred.mathworks.com>...

>> I want to align some strings in a GUI. I have the following example:
>>
>>
>> h={'Product Name' 'Price' 'Code'}
>> j={'Newcastle' '20' 'EU20'}
>> bongo=[h ;j]
>> set(h,'string',sprintf('%s %s\n',bongo{:}))% h
>> is a handle to a text box.
>>
>> I want the left column to be vertical aligned. Both h and j har
>> cellarrays which contains many numbers and characters. Maybe I could
>> make some code that extend the strings in the left column if the
>> length of the strings are different?

> Does anybody know how to fix my problem?

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/uicontrol_props.html#bqxoims

HorizontalAlignment

     left | {center} | right

     Horizontal alignment of label string. This property determines the
justification of the text defined for the String property (the uicontrol
label):

         *

           left — Text is left justified with respect to the uicontrol.
         *

           center — Text is centered with respect to the uicontrol.
         *

           right — Text is right justified with respect to the uicontrol.

     On Microsoft Windows systems, this property affects only edit and
text uicontrols.

Subject: Alignment of strings

From: Yair Altman

Date: 23 May, 2010 20:18:04

Message: 4 of 5

Walter Roberson <roberson@hushmail.com> wrote ...
> HorizontalAlignment
> left | {center} | right
> On Microsoft Windows systems, this property affects only edit and
> text uicontrols.

Since the OP had a textbox, this will indeed solve the OP's problem. But for anyone who is interested, the HorizontalAlignment can be set for all other uicontrols using their underlying Java component, which can be retrieved via the FindJObj utility on the File Exchange.

The same Java object can also be used to set the VerticalAlignment property and quite a few other useful properties that Matlab does not expose.

Yair Altman
http://UndocumentedMatlab.com

Subject: Alignment of strings

From: jens

Date: 28 May, 2010 06:03:08

Message: 5 of 5

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <htc2hs$2mv$1@fred.mathworks.com>...
> Walter Roberson <roberson@hushmail.com> wrote ...
> > HorizontalAlignment
> > left | {center} | right
> > On Microsoft Windows systems, this property affects only edit and
> > text uicontrols.
>
> Since the OP had a textbox, this will indeed solve the OP's problem. But for anyone who is interested, the HorizontalAlignment can be set for all other uicontrols using their underlying Java component, which can be retrieved via the FindJObj utility on the File Exchange.
>
> The same Java object can also be used to set the VerticalAlignment property and quite a few other useful properties that Matlab does not expose.
>
> Yair Altman
> http://UndocumentedMatlab.com

Thanks Yair and Walter

Jens

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us