Create a PushButton with text

Hi,
I can add an image to a PushButton and some text (which overlap the image). However I need to have text next to the Image in the same PushButton. In the past in c# I created a button with text and an image I was onder how can I do this in matlab. Using OOP we should be able to inherit from handle graphic objects but this dont seems the case. How can I produce a button like this?

1 Kommentar

Adam Danz
Adam Danz am 28 Apr. 2020
This is easy to do in AppDesigner. The image is loaded from the Icon property and then you can use the IconAlignment to position the image relative to the text (demonstrated here).

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 12 Jan. 2016
Bearbeitet: Jan am 17 Jan. 2016

2 Stimmen

You can use the HTML methods to customize uicontrol's:
pic = fullfile(matlabroot, ...
'\toolbox\shared\dastudio\@DAStudio\@ViewmarkManager\spinner.gif');
pic = strrep(pic, '\', '/');
uicontrol('Style', 'PushButton', 'Position', [10, 10, 200, 50], ...
'String', ['<html><img src = "file:/', pic, '"> Hello!'])
Creating a table inside the button is a powerful alternative also.

3 Kommentare

Armindo
Armindo am 12 Jan. 2016
Hi Jan,
thank you for the help. Is possibel to put the text up (at the midle of the button height) insted to be near the bottom?
Jan
Jan am 17 Jan. 2016
@Armindo: You see, that the formatting is done in HTML. Then the standard HTML styles are working, here the align parameter:
...
'String', ['<html><img align="middle" src="file:/', pic, '"> Hello!']
Armindo
Armindo am 21 Jan. 2016
Thank you very much for the help. Solved.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 12 Jan. 2016

Kommentiert:

am 28 Apr. 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by