Got Questions? Get Answers.
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:
rowname aligning

Subject: rowname aligning

From: sujata

Date: 4 Aug, 2012 08:26:09

Message: 1 of 3

Hi

I have a datatable in a GUI. I use the command

set(handles.datatable,'RowName',rownames)

then in the gui it puts the rownames in the rowheaders, but it places the rownames in the middle of the row header. How can I place the rownames to be aligned to the left and adjusts for optimal length?

Thanks for any help

Subject: rowname aligning

From: dpb

Date: 5 Aug, 2012 14:41:21

Message: 2 of 3

On 8/4/2012 3:26 AM, sujata wrote:
> Hi
> I have a datatable in a GUI. I use the command
>
> set(handles.datatable,'RowName',rownames)
>
> then in the gui it puts the rownames in the rowheaders, but it places
> the rownames in the middle of the row header. How can I place the
> rownames to be aligned to the left and adjusts for optimal length?

Don't know the objects in the GUI but the text objects underlying
title() etc. have a [Horizonatl|Vertical]Alignment property. Assuming
the GUI uses the same, give it a go.

You can see the available properties for the object by simply doing a
set() on the handle. You may need to look at the objects in the
'children' handle to find the appropriate text object in question.

--

Subject: rowname aligning

From: matt dash

Date: 5 Aug, 2012 16:33:12

Message: 3 of 3

"sujata" <sujatagp@gmail.com> wrote in message <jvimb1$t7n$1@newscl01ah.mathworks.com>...
> Hi
>
> I have a datatable in a GUI. I use the command
>
> set(handles.datatable,'RowName',rownames)
>
> then in the gui it puts the rownames in the rowheaders, but it places the rownames in the middle of the row header. How can I place the rownames to be aligned to the left and adjusts for optimal length?
>
> Thanks for any help

Unfortunately this is not an easy thing to do. Here's an example that works for me. You'll need to download findjobj first: http://www.mathworks.com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects

%make a table
f=figure;
t=uitable();
set(t,'Data',magic(4),'RowName',{'kjhkjh','asdfasd','asdfasdfasdf','sfasdfasdf'})

%get java stuff:
jscroll=findjobj(t);
rhv=jscroll.getComponent(4); %row header viewport
rh=rhv.getComponent(0); %row header table

%resize header:
headerWidth=200; %the width you want for the rowheader in pixels
rhHeight=rh.getPreferredSize.height;
rh.setPreferredSize(java.awt.Dimension(headerWidth,rhHeight))
rh.setSize(java.awt.Dimension(headerWidth,rhHeight))
rhv.setPreferredSize(java.awt.Dimension(headerWidth,rhHeight))
rhv.setSize(java.awt.Dimension(headerWidth,rhHeight))
rhv.doLayout;

%realign header:
rend=rh.getCellRenderer(1,0);
rend.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);

jscroll.repaint %apply changes

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