<?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/"
	xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Prevent popup menu dismissal</title>
	<atom:link href="http://explodingpixels.wordpress.com/2008/11/10/prevent-popup-menu-dismissal/feed/" rel="self" type="application/rss+xml" />
	<link>http://explodingpixels.wordpress.com/2008/11/10/prevent-popup-menu-dismissal/</link>
	<description>Exposing the pixels behind beautiful user interfaces</description>
	<lastBuildDate>Mon, 09 Nov 2009 14:49:09 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ken</title>
		<link>http://explodingpixels.wordpress.com/2008/11/10/prevent-popup-menu-dismissal/#comment-308</link>
		<dc:creator>Ken</dc:creator>
		<pubDate>Wed, 19 Nov 2008 12:04:54 +0000</pubDate>
		<guid isPermaLink="false">http://explodingpixels.wordpress.com/?p=385#comment-308</guid>
		<description>Great catch Claudio! I&#039;v updated the code with a slightly different approach than you suggested.

-Ken</description>
		<content:encoded><![CDATA[<p>Great catch Claudio! I&#8217;v updated the code with a slightly different approach than you suggested.</p>
<p>-Ken</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Claudio Rosati</title>
		<link>http://explodingpixels.wordpress.com/2008/11/10/prevent-popup-menu-dismissal/#comment-307</link>
		<dc:creator>Claudio Rosati</dc:creator>
		<pubDate>Wed, 19 Nov 2008 08:32:01 +0000</pubDate>
		<guid isPermaLink="false">http://explodingpixels.wordpress.com/?p=385#comment-307</guid>
		<description>Hi,

I&#039;ve implemented your suggestions using the button&#039;s ActionListener instead of the MouseListener. All fine but if I have two of such buttons in a toolbar and, once a popup menu is visible, I click on the other button, the first one remains selected. To solve the problem I&#039;ve added a PropertyChangeListener to the menu, listening for the &quot;visible&quot; property, in order to force the button to be unselected when visible is false.

This is the implementation, where createToggleToolBarButton creates a toggle button with the given ActionListener, 

public JToggleButton createToolBarButton ( final JPopupMenu menu )
{

    final JToggleButton button = createToggleToolBarButton(
        new ActionListener() {
            public void actionPerformed ( ActionEvent e ) {
                if ( ((JToggleButton) e.getSource()).isSelected() )
                    menu.show((Component) e.getSource(), 0, ((Component) e.getSource()).getHeight());
                else
                    menu.setVisible(false);
            }
        }
    );

    menu.addPopupMenuListener(
        new PopupMenuListener() {
            public void popupMenuWillBecomeVisible ( PopupMenuEvent e ) {
            }
            public void popupMenuWillBecomeInvisible ( PopupMenuEvent e ) {
            }
            public void popupMenuCanceled ( PopupMenuEvent e ) {
                button.setSelected(false);
            }
        }
    );
    menu.addPropertyChangeListener(
        &quot;visible&quot;, 
        new PropertyChangeListener() {
            public void propertyChange ( PropertyChangeEvent e ) {
                if ( Boolean.FALSE.equals(e.getNewValue()) )
                    button.setSelected(false);
            }
        }
    );

    // Install a special client property on the button to prevent it from
    // closing of the popup when the down arrow is pressed.
    JComboBox box = new JComboBox();
    Object preventHide = box.getClientProperty(&quot;doNotCancelPopup&quot;);

    button.putClientProperty(&quot;doNotCancelPopup&quot;, preventHide);

    return button;

}</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I&#8217;ve implemented your suggestions using the button&#8217;s ActionListener instead of the MouseListener. All fine but if I have two of such buttons in a toolbar and, once a popup menu is visible, I click on the other button, the first one remains selected. To solve the problem I&#8217;ve added a PropertyChangeListener to the menu, listening for the &#8220;visible&#8221; property, in order to force the button to be unselected when visible is false.</p>
<p>This is the implementation, where createToggleToolBarButton creates a toggle button with the given ActionListener, </p>
<p>public JToggleButton createToolBarButton ( final JPopupMenu menu )<br />
{</p>
<p>    final JToggleButton button = createToggleToolBarButton(<br />
        new ActionListener() {<br />
            public void actionPerformed ( ActionEvent e ) {<br />
                if ( ((JToggleButton) e.getSource()).isSelected() )<br />
                    menu.show((Component) e.getSource(), 0, ((Component) e.getSource()).getHeight());<br />
                else<br />
                    menu.setVisible(false);<br />
            }<br />
        }<br />
    );</p>
<p>    menu.addPopupMenuListener(<br />
        new PopupMenuListener() {<br />
            public void popupMenuWillBecomeVisible ( PopupMenuEvent e ) {<br />
            }<br />
            public void popupMenuWillBecomeInvisible ( PopupMenuEvent e ) {<br />
            }<br />
            public void popupMenuCanceled ( PopupMenuEvent e ) {<br />
                button.setSelected(false);<br />
            }<br />
        }<br />
    );<br />
    menu.addPropertyChangeListener(<br />
        &#8220;visible&#8221;,<br />
        new PropertyChangeListener() {<br />
            public void propertyChange ( PropertyChangeEvent e ) {<br />
                if ( Boolean.FALSE.equals(e.getNewValue()) )<br />
                    button.setSelected(false);<br />
            }<br />
        }<br />
    );</p>
<p>    // Install a special client property on the button to prevent it from<br />
    // closing of the popup when the down arrow is pressed.<br />
    JComboBox box = new JComboBox();<br />
    Object preventHide = box.getClientProperty(&#8220;doNotCancelPopup&#8221;);</p>
<p>    button.putClientProperty(&#8220;doNotCancelPopup&#8221;, preventHide);</p>
<p>    return button;</p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ken</title>
		<link>http://explodingpixels.wordpress.com/2008/11/10/prevent-popup-menu-dismissal/#comment-306</link>
		<dc:creator>Ken</dc:creator>
		<pubDate>Tue, 18 Nov 2008 00:44:20 +0000</pubDate>
		<guid isPermaLink="false">http://explodingpixels.wordpress.com/?p=385#comment-306</guid>
		<description>Hi Paul,

You can use pop-down menus in a variety of places. For example, &lt;a href=&quot;http://images.apple.com/iwork/keynote/images/keynote_gallery01_20070807.jpg&quot; rel=&quot;nofollow&quot;&gt;Apple&#039;s Keynote&lt;/a&gt; (and various other iApps) use pop-down menus in the toolbar. &lt;a href=&quot;http://images.apple.com/macosx/features/images/finder_gallery01_20071016.jpg&quot; rel=&quot;nofollow&quot;&gt;Apple&#039;s Finder&lt;/a&gt; also uses pop-down menus to access things like the current path and miscellaneous actions.

If you want to create the Keynote style of pop-down menu using &lt;a href=&quot;http://code.google.com/p/macwidgets/&quot; rel=&quot;nofollow&quot;&gt;Mac Widgets for Java&lt;/a&gt;, use the &lt;a href=&quot;http://exploding-pixels.com/google_code/javadoc/com/explodingpixels/macwidgets/MacButtonFactory.html&quot; rel=&quot;nofollow&quot;&gt;MacButtonFactory.makeUnifiedToolBarButton(AbstractButton button)&lt;/a&gt;. The icon that you supply should already include the drop down arrow.

Your right, though, in that this is somewhat like having menus at the frame level.</description>
		<content:encoded><![CDATA[<p>Hi Paul,</p>
<p>You can use pop-down menus in a variety of places. For example, <a href="http://images.apple.com/iwork/keynote/images/keynote_gallery01_20070807.jpg" rel="nofollow">Apple&#8217;s Keynote</a> (and various other iApps) use pop-down menus in the toolbar. <a href="http://images.apple.com/macosx/features/images/finder_gallery01_20071016.jpg" rel="nofollow">Apple&#8217;s Finder</a> also uses pop-down menus to access things like the current path and miscellaneous actions.</p>
<p>If you want to create the Keynote style of pop-down menu using <a href="http://code.google.com/p/macwidgets/" rel="nofollow">Mac Widgets for Java</a>, use the <a href="http://exploding-pixels.com/google_code/javadoc/com/explodingpixels/macwidgets/MacButtonFactory.html" rel="nofollow">MacButtonFactory.makeUnifiedToolBarButton(AbstractButton button)</a>. The icon that you supply should already include the drop down arrow.</p>
<p>Your right, though, in that this is somewhat like having menus at the frame level.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Taylor</title>
		<link>http://explodingpixels.wordpress.com/2008/11/10/prevent-popup-menu-dismissal/#comment-304</link>
		<dc:creator>Paul Taylor</dc:creator>
		<pubDate>Mon, 17 Nov 2008 23:53:08 +0000</pubDate>
		<guid isPermaLink="false">http://explodingpixels.wordpress.com/?p=385#comment-304</guid>
		<description>Great ken, I may use this on my reworked toolbar - although not sure what having a menu like this on a toolbar adds to an application unless you have many windows. I suppose its a way for Mac applications to have menus at the frame level like windows/linux without admitting as much</description>
		<content:encoded><![CDATA[<p>Great ken, I may use this on my reworked toolbar &#8211; although not sure what having a menu like this on a toolbar adds to an application unless you have many windows. I suppose its a way for Mac applications to have menus at the frame level like windows/linux without admitting as much</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Swing links of the week: November 16, 2008 : Pushing Pixels</title>
		<link>http://explodingpixels.wordpress.com/2008/11/10/prevent-popup-menu-dismissal/#comment-302</link>
		<dc:creator>Swing links of the week: November 16, 2008 : Pushing Pixels</dc:creator>
		<pubDate>Mon, 17 Nov 2008 17:32:09 +0000</pubDate>
		<guid isPermaLink="false">http://explodingpixels.wordpress.com/?p=385#comment-302</guid>
		<description>[...] Orr explores an interesting usability side of Swing buttons with popup menus. The solution involves using an unpublished &#8220;doNotCancelPopup&#8221; client property [...]</description>
		<content:encoded><![CDATA[<p>[...] Orr explores an interesting usability side of Swing buttons with popup menus. The solution involves using an unpublished &#8220;doNotCancelPopup&#8221; client property [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harald K.</title>
		<link>http://explodingpixels.wordpress.com/2008/11/10/prevent-popup-menu-dismissal/#comment-301</link>
		<dc:creator>Harald K.</dc:creator>
		<pubDate>Sun, 16 Nov 2008 11:51:36 +0000</pubDate>
		<guid isPermaLink="false">http://explodingpixels.wordpress.com/?p=385#comment-301</guid>
		<description>Hi Ken,

Thanks for the quick answer. I&#039;m aware of Werner&#039;s great Quaqua project, but I stopped using it when switching to Java 6. 

After some more hacking, I came up with an easy solution that solves both the issues: Use AWT PopupMenus.

I created a thin wrapper for JPopupMenu that delegates to AWT, so it may be set as the ComponentPopupMenu.

It looks much better!

.k</description>
		<content:encoded><![CDATA[<p>Hi Ken,</p>
<p>Thanks for the quick answer. I&#8217;m aware of Werner&#8217;s great Quaqua project, but I stopped using it when switching to Java 6. </p>
<p>After some more hacking, I came up with an easy solution that solves both the issues: Use AWT PopupMenus.</p>
<p>I created a thin wrapper for JPopupMenu that delegates to AWT, so it may be set as the ComponentPopupMenu.</p>
<p>It looks much better!</p>
<p>.k</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ken</title>
		<link>http://explodingpixels.wordpress.com/2008/11/10/prevent-popup-menu-dismissal/#comment-300</link>
		<dc:creator>Ken</dc:creator>
		<pubDate>Sun, 16 Nov 2008 01:05:08 +0000</pubDate>
		<guid isPermaLink="false">http://explodingpixels.wordpress.com/?p=385#comment-300</guid>
		<description>Hi Harald,

I&#039;m not sure why this isn&#039;t documented...it took me a while to discover it the first time.

Re. JCheckBoxMenuItem: I haven&#039;t looked into fixing the JCheckBoxMenuItem check-mark image, though maybe Werner Randelshofer has in his &lt;a href=&quot;http://www.randelshofer.ch/quaqua/&quot; rel=&quot;nofollow&quot;&gt;Quaqua project&lt;/a&gt;. If not, it would be worth requesting an enhancement from Apple &lt;a href=&quot;https://bugreport.apple.com&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;.

Re. JPopupMenus with rounded corners: I&#039;ve filed an enhancement request with Apple for this. Unfortunately, I&#039;m not aware of any reasonable workarounds for this one.

-Ken</description>
		<content:encoded><![CDATA[<p>Hi Harald,</p>
<p>I&#8217;m not sure why this isn&#8217;t documented&#8230;it took me a while to discover it the first time.</p>
<p>Re. JCheckBoxMenuItem: I haven&#8217;t looked into fixing the JCheckBoxMenuItem check-mark image, though maybe Werner Randelshofer has in his <a href="http://www.randelshofer.ch/quaqua/" rel="nofollow">Quaqua project</a>. If not, it would be worth requesting an enhancement from Apple <a href="https://bugreport.apple.com" rel="nofollow">here</a>.</p>
<p>Re. JPopupMenus with rounded corners: I&#8217;ve filed an enhancement request with Apple for this. Unfortunately, I&#8217;m not aware of any reasonable workarounds for this one.</p>
<p>-Ken</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harald K.</title>
		<link>http://explodingpixels.wordpress.com/2008/11/10/prevent-popup-menu-dismissal/#comment-299</link>
		<dc:creator>Harald K.</dc:creator>
		<pubDate>Sat, 15 Nov 2008 23:51:27 +0000</pubDate>
		<guid isPermaLink="false">http://explodingpixels.wordpress.com/?p=385#comment-299</guid>
		<description>Great tip! 

I once tried to fix a similar problem in a project. After half an hour I decided it wasn&#039;t worth the time.. 
I wonder why this isn&#039;t documented?

Some follow up questions that I&#039;ve been trying to figure out lately, kind of related:
 - How can we have the JCheckBoxMenuItem check icon look like the check icon in the menu bar? Is there a better way than using two pngs?
 - Do you know of a way to have JPopupMenus with rounded corners (and less transparency), like the rest of OS X?


Anyway, thanks a lot for a great blog!


.k</description>
		<content:encoded><![CDATA[<p>Great tip! </p>
<p>I once tried to fix a similar problem in a project. After half an hour I decided it wasn&#8217;t worth the time..<br />
I wonder why this isn&#8217;t documented?</p>
<p>Some follow up questions that I&#8217;ve been trying to figure out lately, kind of related:<br />
 &#8211; How can we have the JCheckBoxMenuItem check icon look like the check icon in the menu bar? Is there a better way than using two pngs?<br />
 &#8211; Do you know of a way to have JPopupMenus with rounded corners (and less transparency), like the rest of OS X?</p>
<p>Anyway, thanks a lot for a great blog!</p>
<p>.k</p>
]]></content:encoded>
	</item>
</channel>
</rss>
