Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Can popup menu events be consumed by other (e.g. background) components?

843804Jan 27 2005 — edited Jan 29 2005
Has anyone seen where popup menu events seem to not get directed to the component that you think should receive them (i.e. foreground components)?

The class below is a test case that you should be able to compile and run which I believe demonstrates this phenomena. The class's javadocs thoroughly explain my test procedure. By the way, you will need JDK 1.5+ in order to compile and run this, since I use the new JComponent methods setComponentPopupMenu and setInheritsPopupMenu (if you are unfamiliar with this, see the excellent article http://www-106.ibm.com/developerworks/library/j-tiger05124/?ca=dnt-522).

The important point is that, at least on my machine, no matter where you click inside the JFrame, no popup menu appears except when you right click over the JTextArea. But I would have thought that a popup menu should always appear, regardless of where inside the JFrame that I right click. I am particularly puzzled as to why the JLabel, which is treated the same as the JTextArea, fails to get popup menu events.

My interpretation is that this must be because some other (background) component consumed the popup event before it can reach my components which have associated popup menus.

Or am I just not understanding how to use the popup menu api?

Or is the new setComponentPopupMenu and setInheritsPopupMenu functionality buggy?
import java.awt.Color;

import javax.swing.*;
import javax.swing.event.*;


/**
* This class bring up a new JFrame whose ContentPane contains
* a new JPanel which contains
* a new JLabel and a new JTextArea.
* <p>
* The JFrame's content pane's background is set to red, and the JPanel's background is set to green,
* so that you can visually see everywhere each extends.
* (As expected, the JPanel fills the entirety of the inside of the JFRame.)
* <p>
* Dedicated JPopupMenu instances are assigned to all of the JFrame's panes (content, glass, layered, and root)
* as well as the JPanel.
* The JLabel and JTextArea are assigned to inherit their PopupMenu,
* which here means that they will use the JPanel's PopupMenu.
* <p>
* The popup menus all contain just a single item whoch does nothing except state the source of the popup event.
* A given popup menu instance also has an associated PopupMenuListener which prints events to System.out,
* identifying the event source in the process,
* so that if it was generated but was somehow obscured, then you can tell from looking at System.out.
* <p>
* The expected outcome of running this class is that you should be able to mouse right click
* (this assumes Windoze is the OS) anywhere inside the JFrame and a popup menu should appear.
* More specifically, that popup menu should always have a single item labeled "Event from JPanel"
* because the JPanel fills up all the inside of the JFrame
* and all of its children inherit their popup menu from it.
* <p>
* What happens in reality is different:
* if you right click directly over the JTextArea, the expected popup menu appears,
* but if you right click over anywhere else (e.g. directly over the JLabel), nothing appears.
* <p>
* What must be happening is that some other component is first receiving many of the mouse events and consuming them.
* <p>
* @author Brent Boyer
* @see <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4465870">A possibly related bug report</a>
*/
public class PopupMenuBug {
	
 
	public static void main(String[] args) throws Exception {
		buildGui();
	}
	
 
	private static void buildGui() {
		JFrame frame = new JFrame();
		frame.setSize(600, 500);
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		frame.getContentPane().setBackground( Color.RED );
		
		((JComponent) frame.getContentPane()).setComponentPopupMenu( new PopupMenuLabeled("Event from ContentPane") );
		((JComponent) frame.getGlassPane()).setComponentPopupMenu( new PopupMenuLabeled("Event from GlassPane") );		
		frame.getLayeredPane().setComponentPopupMenu( new PopupMenuLabeled("Event from LayeredPane") );
		frame.getRootPane().setComponentPopupMenu( new PopupMenuLabeled("Event from RootPane") );
		
		frame.getContentPane().add( buildItems() );

		frame.setVisible(true);
	}
	
 
	private static JComponent buildItems() {
		JPanel jpanel = new JPanel();
		jpanel.setBackground( Color.GREEN );
		jpanel.setComponentPopupMenu( new PopupMenuLabeled("Event from JPanel") );
				
		jpanel.add( buildItem1() );
		jpanel.add( Box.createHorizontalStrut(20) );
		jpanel.add( buildItem2() );
		
		return jpanel;
	}
	
 
	private static JComponent buildItem1() {
		JLabel label = new JLabel("Label");
		label.setInheritsPopupMenu(true);
		return label;
	}
	
 
	private static JComponent buildItem2() {
		JTextArea textArea = new JTextArea("JTextArea", 20, 20);
		textArea.setInheritsPopupMenu(true);
		return textArea;
	}
	
	
	private static class PopupMenuLabeled extends JPopupMenu {
		private static final long serialVersionUID = 1;
		
		private PopupMenuLabeled(final String label) {
			add( new JMenuItem( label ) );
			
			addPopupMenuListener( new PopupMenuListener() {
				public void popupMenuWillBecomeVisible(PopupMenuEvent e) { System.out.println( label + ": popupMenuWillBecomeVisible" ); }
				public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { System.out.println( label + ": popupMenuWillBecomeInvisible" + "\n" ); }
				public void popupMenuCanceled(PopupMenuEvent e) { System.out.println( label + ": popupMenuCanceled" ); }
			} ); 
		}
	}


}

Comments

user12021897
... going different way now: Configured hardware raid5 for the 3 disks, working perfect.
463096
OVM Local Disk Tips

[] You must have at least two physical disks in your OVM server. Two partitons on
one disk will not work. OVM Server will claim the entire first disk for
installation. You can then use the second disk as local storage, if, and only if,
the second disk is completely blank. If there are any partitions of any type on
the second disk, it will not be recognized under OVM as a local disk.

[] Local disks are not supported by Oracle. Using local disks for anything other
than basic and preliminary learning of how to work with OVM with a limited
hardware inventory such as a couple of laptops or desktops, is a very bad idea.

[] Verify all partions are removed from 2nd non-OS local disk on OVM Server.
$ fdisk -l

On Ubuntu Linux, use sudo to prefix each command, as in:
$ sudo fdisk -l
(enter root password)

If your first disk is /dev/sda and your second disk is /dev/sdb,
use fdisk to remove all partitions on the second disk, /dev/sdb.
$ fdisk /dev/sdb
p(rint)
d(elete partition) 1, d 2, d 3, etc.
w(rite)
q(uit)

[] multipathd needs to be running on your OVM Server, even if no
multipath storage exists on the system.
# chkconfig --list multipathd
# chkconfig multipathd on
# chkconfig --list multipathd
# service multipathd restart

[] verify multipathd lists the local storage on your OVM Server.
# multipath -ll
# multipath -ll -v[1..3] (Verying levels of detail)

[] verify storage discovery works
# storage_discover --infoDumpType=disk_XML

[] I run OVMM (OVM Manager) on a laptop with 4GB of RAM as a VirtualBox VM. Slow
but functional. YMMV.

[] On the OVMM OS (physical OS or VM), ensure iptables are disabled.
# chkconfig --list iptables
# chkconfig iptables off
# chkconfig --list iptables
# service iptables stop

[] Rescan the Physical Disks on the OVM Server from OVMM.

[] Create repository on local disk per Appendix C of OVM Quick Start Guide.
Happy learning.
911168
A couple of issues:

"Create repository on local disk per Appendix C of OVM Quick Start Guide."

That only used to be true. It got dropped in the 3.0.3 version of the doc. To find Appendix C, you must look in an older version of the guide, ovm3-quick-start-guide-wp-516656.pdf, at: http://www.oracle.com/technetwork/server-storage/vm/ovm3-quick-start-guide-wp-516656.pdf

"Local disks are not supported by Oracle"
Untrue. See above mentioned doc.
Alan3
I found all that was necessary is to partition your local array in your RAID controller into two or more virtual disks (BEFORE installing the VM Server.).
Only present one of the virtual disks to the VM Server install. The other(s) will then be available to use as local storage within the VM Manager.
Of course the first time through the server setup I got it wrong... but that's history now...
user10465987
Hello.. I've tried multiple times too, to get the local disks to be discovered, but having no luck.

Hardware.. IBM x346 server.. 2 x 73gb drives (mirror)... 4 x 146gb drives (raid 5).

Install OVM Server 3.0.3 server and it installs to /dev/sba no problem... It trys to install the / to the /dev/sdb, but I remove it and put it back on /dev/sba, so that nothing but Free Space is showing for /dev/sdb.

After it's all installed/rebooted, etc.. I go to the OVM Mgr (3.0.3 build 240) server and discover the new box.
It sees the oelvmibm02 server. I'm able to add it to the ibm-pool, and when I discover Physical Disks.. nothing shows.

I've ensured that iptables is OFF for the vm mgr server.

I've looked at the multipathd service on VM Svr.. it's running.
However, when I issue the command multipath -ll
here is what I get:
DM multipath kernel driver not loaded

I've reinstalled OVM Svr 3.0.3 multiple times on this box, with different configuration trying to get it to recognize the 2nd array so I can have a repository, but nothing seems to work.

Any ideas on what to try next? I'm all open for suggestions.

Edited by: user10465987 on Apr 17, 2012 4:11 PM
939273
don't know if this affected others on this list but this one caused me to not see local disk

6.4.3. Local SAS Hard Disks Not Supported for Storage
If you use an Oracle VM Server with local SAS hard disks installed, empty disks of this type are not discovered in Oracle VM Manager and therefore cannot be used as local storage. This is caused by the fact that local SAS disks are not associated with a (local) storage array. SAS hard disks can therefore only be used for installing Oracle VM Server on them; they cannot be used for storage repositories, server pool file systems or raw LUNs as virtual machine disks.
1 - 6
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Feb 26 2005
Added on Jan 27 2005
2 comments
389 views