How to align text to the top of the button in Matlab GUI?

对着背影说爱祢 提交于 2019-12-23 10:08:26

问题


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


回答1:


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 );




回答2:


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

  1. Add extra return characters after your main text, so that the real text ends up at the top while the whole text remains centred
  2. (REALLY horrible) Create an image with your text right at the top, and use this with the CData property of the button.


来源:https://stackoverflow.com/questions/8225543/how-to-align-text-to-the-top-of-the-button-in-matlab-gui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!