How to align text to the top of the button in Matlab GUI?
-
06-03-2021 - |
Question
I have a GUI with big buttons and wouls like to align the text in the button to the top, all I found is "horizontal alignment" property. Thanks...
La solution
You need to access the underlying Java Swing component (I am using FINDJOBJ function):
figure('Menubar','none', 'Position',[200 200 300 200])
h = uicontrol('Style','pushbutton', 'String','click', ...
'Units','normalized', 'Position',[0.3 0.3 0.5 0.5]);
jh = findjobj(h);
jh.setVerticalAlignment( javax.swing.AbstractButton.BOTTOM );
Autres conseils
I'm afraid I think you can't do this - text is always vertically aligned at the middle on a uicontrol
. The only hacks I can think of that might achieve something like what you want are
- Add extra return characters after your main text, so that the real text ends up at the top while the whole text remains centred
- (REALLY horrible) Create an image with your text right at the top, and use this with the
CData
property of the button.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow