|
"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
|