<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Setting listbox mouse actions	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=setting-listbox-mouse-actions</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Fri, 28 Jun 2019 16:17:34 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-485075</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Fri, 28 Jun 2019 16:17:34 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=503#comment-485075</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-484657&quot;&gt;Ozgu&lt;/a&gt;.

@Ozgu - yes you can but only if you create a dedicated Java cellrenderer class for this (i.e., not in pure Matlab)]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-484657">Ozgu</a>.</p>
<p>@Ozgu &#8211; yes you can but only if you create a dedicated Java cellrenderer class for this (i.e., not in pure Matlab)</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Ozgu		</title>
		<link>https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-484657</link>

		<dc:creator><![CDATA[Ozgu]]></dc:creator>
		<pubDate>Tue, 25 Jun 2019 17:48:47 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=503#comment-484657</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-484474&quot;&gt;Yair Altman&lt;/a&gt;.

Thank you for your answer Yair,

Ok. Can I add a mouse hover event for each item for Jcombobox

Thanks again

Ozgu]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-484474">Yair Altman</a>.</p>
<p>Thank you for your answer Yair,</p>
<p>Ok. Can I add a mouse hover event for each item for Jcombobox</p>
<p>Thanks again</p>
<p>Ozgu</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-484474</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Mon, 24 Jun 2019 13:22:31 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=503#comment-484474</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-483998&quot;&gt;Ozgu&lt;/a&gt;.

@Ozgu - combobox popups are not the same as listboxes, although they share some common aspects. For example, combo-box items do not have tooltips by default - only the main edit-box component of the combo-box has a tooltip. It is indeed possible to use Java to display a tooltip for each combo-box item (using a dedicated renderer, &lt;a href=&quot;https://stackoverflow.com/questions/480261/java-swing-mouseover-text-on-jcombobox-items&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;example 1&lt;/a&gt;, &lt;a href=&quot;http://esus.com/showing-a-different-tooltip-for-every-item-in-a-jcombobox&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;example 2&lt;/a&gt;), but this is not easy to achieve in Matlab, and is beyond the scope of this post.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-483998">Ozgu</a>.</p>
<p>@Ozgu &#8211; combobox popups are not the same as listboxes, although they share some common aspects. For example, combo-box items do not have tooltips by default &#8211; only the main edit-box component of the combo-box has a tooltip. It is indeed possible to use Java to display a tooltip for each combo-box item (using a dedicated renderer, <a href="https://stackoverflow.com/questions/480261/java-swing-mouseover-text-on-jcombobox-items" target="_blank" rel="nofollow">example 1</a>, <a href="http://esus.com/showing-a-different-tooltip-for-every-item-in-a-jcombobox" target="_blank" rel="nofollow">example 2</a>), but this is not easy to achieve in Matlab, and is beyond the scope of this post.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Ozgu		</title>
		<link>https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-483998</link>

		<dc:creator><![CDATA[Ozgu]]></dc:creator>
		<pubDate>Thu, 20 Jun 2019 19:52:03 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=503#comment-483998</guid>

					<description><![CDATA[Hi Yair,

I applied dynamic tooltip example on jcombobox, but there is no 
&quot;locationToIndex&quot; property for jcombobox.

How can I overcome this problem?

Thanks 

Ozgu]]></description>
			<content:encoded><![CDATA[<p>Hi Yair,</p>
<p>I applied dynamic tooltip example on jcombobox, but there is no<br />
&#8220;locationToIndex&#8221; property for jcombobox.</p>
<p>How can I overcome this problem?</p>
<p>Thanks </p>
<p>Ozgu</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-416718</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Tue, 21 Nov 2017 10:50:59 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=503#comment-416718</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-416680&quot;&gt;claudio&lt;/a&gt;.

@Claudio - I don&#039;t know why you posted this question here - it seems to relate to popup/dropdown menus and not listboxes. In any case, such menu items &lt;a href=&quot;https://stackoverflow.com/questions/4162980/can-i-modify-jcombobox-popup-background-color-of-an-existing-object&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;cannot be modified&lt;/a&gt; using the &lt;i&gt;setBackground&lt;/i&gt; method, you need to either use a custom Java cell-renderer object, or modify the menu string to include HTML background, for example:
&lt;pre lang=&quot;matlab&quot;&gt;menuCheck.setText(sprintf(&#039;&lt;html&gt;&lt;body bgcolor=rgb(%d,%d,%d)&gt;Check recording&#039;,bgcolor))&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-416680">claudio</a>.</p>
<p>@Claudio &#8211; I don&#8217;t know why you posted this question here &#8211; it seems to relate to popup/dropdown menus and not listboxes. In any case, such menu items <a href="https://stackoverflow.com/questions/4162980/can-i-modify-jcombobox-popup-background-color-of-an-existing-object" target="_blank" rel="nofollow">cannot be modified</a> using the <i>setBackground</i> method, you need to either use a custom Java cell-renderer object, or modify the menu string to include HTML background, for example:</p>
<pre lang="matlab">menuCheck.setText(sprintf('<html><body bgcolor=rgb(%d,%d,%d)>Check recording',bgcolor))</body></html></pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: claudio		</title>
		<link>https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-416680</link>

		<dc:creator><![CDATA[claudio]]></dc:creator>
		<pubDate>Mon, 20 Nov 2017 11:22:47 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=503#comment-416680</guid>

					<description><![CDATA[Hi Yair

how can I change background color for jmenu described in the previous example? 
I try 
&lt;pre lang=&quot;matlab&quot;&gt;
menuCheck = javax.swing.JMenuItem(&#039;Check recording&#039;);
bgcolor = get(gcf,&#039;Color&#039;);   % background color = white 
menuCheck.setBackground(java.awt.Color(bgcolor(1),bgcolor(2),bgcolor(3)));
menuCheck.repaint
&lt;/pre&gt;

But the classic gray background color does not change...]]></description>
			<content:encoded><![CDATA[<p>Hi Yair</p>
<p>how can I change background color for jmenu described in the previous example?<br />
I try </p>
<pre lang="matlab">
menuCheck = javax.swing.JMenuItem('Check recording');
bgcolor = get(gcf,'Color');   % background color = white 
menuCheck.setBackground(java.awt.Color(bgcolor(1),bgcolor(2),bgcolor(3)));
menuCheck.repaint
</pre>
<p>But the classic gray background color does not change&#8230;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan		</title>
		<link>https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-357198</link>

		<dc:creator><![CDATA[Jonathan]]></dc:creator>
		<pubDate>Fri, 18 Sep 2015 14:02:50 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=503#comment-357198</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-357181&quot;&gt;Jonathan&lt;/a&gt;.

Thanks Yair,

I looked at your book and I found some part of the modification I should implement on p. 414:

&lt;pre lang=&#039;matlab&#039;&gt;
hFig = figure;

% Prepare the list of JLabel objects
iconsFolder = fullfile(matlabroot,&#039;toolbox/matlab/icons&#039;); 
imgs = dir(fullfile(iconsFolder,&#039;*.gif&#039;));
for idx=1 : length(imgs)
    iconFilename=fullfile(iconsFolder, imgs(idx).name); 
    iconTooltip=[&#039;Item-specific tooltip: &#039; imgs(idx).name]; 
    jLabels{idx} = javax.swing.JLabel; 
    jLabels{idx}.setIcon(javax.swing.ImageIcon(iconFilename)); 
    jLabels{idx}.setText(imgs(idx).name); 
    jLabels{idx}.setToolTipText(iconTooltip);
end

% Set the JLabel objects in the model 
set(jPopup,&#039;String&#039;,{imgs.name}); % ensure consistent HG size 
model=javax.swing.DefaultComboBoxModel; %not DefaultListModel 
for idx=1:length(imgs)
        model.addElement(jLabels{idx});
end 
jPopup.setModel(model);

% Set the display Renderer
% Note: LabelLisitBoxRenderer was presented in section 6.6 above 
jPopup.setRenderer(LabelListBoxRenderer); %not setCellRenderer() 
jPopup.setFixedCellHeight(16); % give the icons some space... 
jPopup.setMaximumRowCount(8); % override the default 20
&lt;/pre&gt;

I added the hFig = figure; at the beginning but there is still some part of the code missing especially the part that define jPopup and where you place it. Can you give me some hint ?

Thanks in advance

Jonathan]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-357181">Jonathan</a>.</p>
<p>Thanks Yair,</p>
<p>I looked at your book and I found some part of the modification I should implement on p. 414:</p>
<pre lang='matlab'>
hFig = figure;

% Prepare the list of JLabel objects
iconsFolder = fullfile(matlabroot,'toolbox/matlab/icons'); 
imgs = dir(fullfile(iconsFolder,'*.gif'));
for idx=1 : length(imgs)
    iconFilename=fullfile(iconsFolder, imgs(idx).name); 
    iconTooltip=['Item-specific tooltip: ' imgs(idx).name]; 
    jLabels{idx} = javax.swing.JLabel; 
    jLabels{idx}.setIcon(javax.swing.ImageIcon(iconFilename)); 
    jLabels{idx}.setText(imgs(idx).name); 
    jLabels{idx}.setToolTipText(iconTooltip);
end

% Set the JLabel objects in the model 
set(jPopup,'String',{imgs.name}); % ensure consistent HG size 
model=javax.swing.DefaultComboBoxModel; %not DefaultListModel 
for idx=1:length(imgs)
        model.addElement(jLabels{idx});
end 
jPopup.setModel(model);

% Set the display Renderer
% Note: LabelLisitBoxRenderer was presented in section 6.6 above 
jPopup.setRenderer(LabelListBoxRenderer); %not setCellRenderer() 
jPopup.setFixedCellHeight(16); % give the icons some space... 
jPopup.setMaximumRowCount(8); % override the default 20
</pre>
<p>I added the hFig = figure; at the beginning but there is still some part of the code missing especially the part that define jPopup and where you place it. Can you give me some hint ?</p>
<p>Thanks in advance</p>
<p>Jonathan</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-357187</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Fri, 18 Sep 2015 10:18:02 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=503#comment-357187</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-357181&quot;&gt;Jonathan&lt;/a&gt;.

@Jonathan - popups do not use a viewport in the same manner as a listbox. You can have more control over the appearance and behavior if you use JIDE comboboxes directly, as briefly &lt;a href=&quot;http://undocumentedmatlab.com/blog/using-jide-combo-boxes&quot; rel=&quot;nofollow&quot;&gt;explained here&lt;/a&gt; and in more detail in my &lt;a href=&quot;http://undocumentedmatlab.com/books/matlab-java&quot; rel=&quot;nofollow&quot;&gt;Matlab-Java book&lt;/a&gt;.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-357181">Jonathan</a>.</p>
<p>@Jonathan &#8211; popups do not use a viewport in the same manner as a listbox. You can have more control over the appearance and behavior if you use JIDE comboboxes directly, as briefly <a href="http://undocumentedmatlab.com/blog/using-jide-combo-boxes" rel="nofollow">explained here</a> and in more detail in my <a href="http://undocumentedmatlab.com/books/matlab-java" rel="nofollow">Matlab-Java book</a>.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan		</title>
		<link>https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-357181</link>

		<dc:creator><![CDATA[Jonathan]]></dc:creator>
		<pubDate>Fri, 18 Sep 2015 09:52:04 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=503#comment-357181</guid>

					<description><![CDATA[Hi Yair,

First thank you for your amazing website, it has been really useful for me !

I would like to have different tooltips for the different object of my popupmenu.

I tried to use the same idea that you are using for the uicontrol ‘Listbox’ but for a uicontrol ‘Popupmenu’. I just want to have the dynamic tooltips.
I tried to simply replace ‘Listbox’ by ‘Popupmenu&#039; in the code but it does’t work. I got the error :

&lt;pre lang=&#039;matlab&#039;&gt;
No appropriate method, property, or field &#039;getViewport&#039; for class &#039;javahandle_withcallbacks.com.mathworks.hg.peer.ComboboxPeer$MLComboBox&#039;.
&lt;/pre&gt;

I used &lt;code&gt;uiinspect&lt;/code&gt; to check and I saw that there is no getViewport in the jScrollPane when I use the uicontrol ‘Popupmenu’

I am not familiar with java so I have trouble to figure out what I should modify to have the code working with ‘Popupmenu’

Thanks in advance

Jonathan]]></description>
			<content:encoded><![CDATA[<p>Hi Yair,</p>
<p>First thank you for your amazing website, it has been really useful for me !</p>
<p>I would like to have different tooltips for the different object of my popupmenu.</p>
<p>I tried to use the same idea that you are using for the uicontrol ‘Listbox’ but for a uicontrol ‘Popupmenu’. I just want to have the dynamic tooltips.<br />
I tried to simply replace ‘Listbox’ by ‘Popupmenu&#8217; in the code but it does’t work. I got the error :</p>
<pre lang='matlab'>
No appropriate method, property, or field 'getViewport' for class 'javahandle_withcallbacks.com.mathworks.hg.peer.ComboboxPeer$MLComboBox'.
</pre>
<p>I used <code>uiinspect</code> to check and I saw that there is no getViewport in the jScrollPane when I use the uicontrol ‘Popupmenu’</p>
<p>I am not familiar with java so I have trouble to figure out what I should modify to have the code working with ‘Popupmenu’</p>
<p>Thanks in advance</p>
<p>Jonathan</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-346664</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Sat, 14 Mar 2015 16:45:18 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=503#comment-346664</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-346594&quot;&gt;Ilya&lt;/a&gt;.

@Ilya - perhaps you can get the clicked location (X,Y) and compare this to the knob&#039;s position, ignoring locations outside it.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/setting-listbox-mouse-actions#comment-346594">Ilya</a>.</p>
<p>@Ilya &#8211; perhaps you can get the clicked location (X,Y) and compare this to the knob&#8217;s position, ignoring locations outside it.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
