How we can change horizontal alignment of list box to right in MATLAB R2016 in AppDesigner or GUIDE? There isn't any available property in list box.
Asked
Active
Viewed 567 times
2
-
1Which is it then - App Designer or GUIDE? These are **VERY** different things (one is based on JS/CSS and the other is on Java). If you want to do it with App Designer, you might have to manipulate the `.css` files in `%matlabroot%/toolbox/matlab/uitools/uifigureappjs/release/gbtclient/css/...` With GUIDE it should be fairly easy... – Dev-iL Aug 13 '16 at 09:08
-
@Dev-iL. Currently I'm using AppDesigner . I mentioned two aspects to have a more general question. thanks. – Eghbal Aug 13 '16 at 09:09
-
1Would a solution only in GUIDE be acceptable? – Dev-iL Aug 13 '16 at 09:10
-
@Dev-iL. AppDesigner is better :-) – Eghbal Aug 13 '16 at 09:11
-
@Dev-iL. we have same problem in other components like radio button. – Eghbal Aug 13 '16 at 10:39
1 Answers
1
We can find some clues on how to do this with GUIDE in this UndocumentedMatlab article. We need the findjobj
utility, to get a handle for the Java control. The next steps
function q38930371
hF = figure(...
'Position',[500 500 300 350],...
'Tag','Demo',...
'Menubar','None',...
'Resize','on');
hLb = uicontrol(...
'Parent',hF,...
'String',{ 'Item 1'; 'Item 2'; 'Item 3'; 'Item 4' },...
'Style','listbox',...
'Value',1,...
'Position',[50 50 200 250],...
'Children',[],...
'Tag','listbox1');
% Get a handle to the Java control:
jSp = findjobj(hLb);
% Get the list cell renderer
jCr = jSp.getViewport.getView.getCellRenderer;
% Set the horizontal alignment of the renderer:
% https://docs.oracle.com/javase/7/docs/api/javax/swing/DefaultListCellRenderer.html
jCr.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
% Refresh view:
jSp.repaint
The result:
The App Designer solution can be found in this post.