<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[JavaRanch: Latest posts for the topic "How to display Right-click popup menu in JPanel?"]]></title>
		<link>http://www.coderanch.com/forums/t/2/Swing-AWT-SWT-JFace/display-Right-click-popup-menu</link>
		<description><![CDATA[Latest messages posted in the topic "How to display Right-click popup menu in JPanel?"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>How to display Right-click popup menu in JPanel?</title>
				<description><![CDATA[Hi All,<br /> <br /> In my application, a <a href="http://java.sun.com/javase/6/docs/api/javax/swing/JPanel.html" class="api" title="Java API" target="_new" rel="nofollow">JPanel</a> gets displayed in a <a href="http://java.sun.com/javase/6/docs/api/javax/swing/JWindow.html" class="api" title="Java API" target="_new" rel="nofollow">JWindow</a>. I need to add a right-click menu (with 'Exit' and 'About') in that <a href="http://java.sun.com/javase/6/docs/api/javax/swing/JPanel.html" class="api" title="Java API" target="_new" rel="nofollow">JPanel</a>.<br /> <br /> I am not able to add the popup menu in the <a href="http://java.sun.com/javase/6/docs/api/javax/swing/JPanel.html" class="api" title="Java API" target="_new" rel="nofollow">JPanel</a>.<br /> <br /> Can anybody please help me out??? Any pointer would be helpful.<br /> <br /> Thanks in advance...]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/450603/2005653</guid>
				<link>http://www.coderanch.com/forums/posts/preList/450603/2005653</link>
				<pubDate><![CDATA[Sat, Jun 20 2009 18:38:45 MDT]]></pubDate>
				<author><![CDATA[ujjal dey]]></author>
			</item>
			<item>
				<title>How to display Right-click popup menu in JPanel?</title>
				<description><![CDATA[some info in a similar post here<br /> <br /> <a class="snap_shots" href="http://forums.sun.com/thread.jspa?threadID=5393146&tstart=0" target="_new" rel="nofollow">http://forums.sun.com/thread.jspa?threadID=5393146&tstart=0</a>]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/450603/2005657</guid>
				<link>http://www.coderanch.com/forums/posts/preList/450603/2005657</link>
				<pubDate><![CDATA[Sat, Jun 20 2009 19:12:51 MDT]]></pubDate>
				<author><![CDATA[Michael Dunn]]></author>
			</item>
			<item>
				<title>How to display Right-click popup menu in JPanel?</title>
				<description><![CDATA[This page does a good job of explaining mouse Events, and deals specifically with how to tell if a mouse click event is a right click, once you determine that you can take the appropriate  steps to display your menu.<br /> <br /> <a class="snap_shots" href="http://www.faqs.org/docs/javap/c6/s4.html" target="_blank" rel="nofollow">http://www.faqs.org/docs/javap/c6/s4.html</a><br /> <br /> edit: You'll be probably using a <a href="http://java.sun.com/javase/6/docs/api/javax/swing/JPopupMenu.html" class="api" title="Java API" target="_new" rel="nofollow">JPopupMenu</a>, and probably the show() method of this class to actually display the menu]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/450603/2005662</guid>
				<link>http://www.coderanch.com/forums/posts/preList/450603/2005662</link>
				<pubDate><![CDATA[Sat, Jun 20 2009 19:31:30 MDT]]></pubDate>
				<author><![CDATA[Fred Hamilton]]></author>
			</item>
			<item>
				<title>How to display Right-click popup menu in JPanel?</title>
				<description><![CDATA[<blockquote>
			<div>
				<cite>ujjal dey wrote:</cite>Hi All,<br /> <br /> In my application, a <a href="http://java.sun.com/javase/6/docs/api/javax/swing/JPanel.html" class="api" title="Java API" target="_new" rel="nofollow">JPanel</a> gets displayed in a <a href="http://java.sun.com/javase/6/docs/api/javax/swing/JWindow.html" class="api" title="Java API" target="_new" rel="nofollow">JWindow</a>. I need to add a right-click menu (with 'Exit' and 'About') in that <a href="http://java.sun.com/javase/6/docs/api/javax/swing/JPanel.html" class="api" title="Java API" target="_new" rel="nofollow">JPanel</a>.<br /> <br /> I am not able to add the popup menu in the <a href="http://java.sun.com/javase/6/docs/api/javax/swing/JPanel.html" class="api" title="Java API" target="_new" rel="nofollow">JPanel</a>.<br /> <br /> Can anybody please help me out??? Any pointer would be helpful.<br /> <br /> Thanks in advance...</div>
		</blockquote><br /> <br /> This is a sample test using JPopup.. you can add the pannel.. and change item listener for your purpose.. But first , follow the link that suggested by others to determine and understand your purpose.<br /> <br /> <pre>    
public class PopupTest extends JFrame {

   private JRadioButtonMenuItem items[];
   private Color colorValues[] =
      { Color.blue, Color.yellow, Color.red };

   public PopupTest()
   {
      super( &quot;Using JPopupMenus&quot; );

      final JPopupMenu popupMenu = new JPopupMenu();
      ItemHandler handler = new ItemHandler();
      String colors[] = { &quot;Blue&quot;, &quot;Yellow&quot;, &quot;Red&quot; };
      ButtonGroup colorGroup = new ButtonGroup();
      items = new JRadioButtonMenuItem[ 3 ];

      // construct each menu item and add to popup menu; also
      // enable event handling for each menu item
      for ( int i = 0; i &lt; items.length; i++ ) {
         items[ i ] = new JRadioButtonMenuItem( colors[ i ] );
         popupMenu.add( items[ i ] );
         colorGroup.add( items[ i ] );
         items[ i ].addActionListener( handler );
      }

      getContentPane().setBackground( Color.white );

      // define a MouseListener for the window that displays
      // a JPopupMenu when the popup trigger event occurs
      addMouseListener(
         new MouseAdapter() {
            public void mousePressed( MouseEvent e )
               { checkForTriggerEvent( e ); }

            public void mouseReleased( MouseEvent e )
               { checkForTriggerEvent( e ); }

            private void checkForTriggerEvent( MouseEvent e )
            {
               if ( e.isPopupTrigger() )
                  popupMenu.show( e.getComponent(),
                                  e.getX(), e.getY() );
            }
         }
      );

      setSize( 300, 200 );
      show();
   }

   public static void main( String args[] )
   {
      PopupTest app = new PopupTest();

      app.addWindowListener(
         new WindowAdapter() {
            public void windowClosing( WindowEvent e )
            {
               System.exit( 0 );
            }
         }
      );
   }

   private class ItemHandler implements ActionListener {
      public void actionPerformed( ActionEvent e )
      {
         // determine which menu item was selected
         for ( int i = 0; i &lt; items.length; i++ )
            if ( e.getSource() == items[ i ] ) {
               getContentPane().setBackground(
                  colorValues[ i ] );
               repaint();
               return;
            }
      }
   }
}
</pre>]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/450603/2006386</guid>
				<link>http://www.coderanch.com/forums/posts/preList/450603/2006386</link>
				<pubDate><![CDATA[Sun, Jun 21 2009 20:29:12 MDT]]></pubDate>
				<author><![CDATA[Ramses Butarbutar]]></author>
			</item>
	</channel>
</rss>
