Java Reference
In-Depth Information
JPopupMenu.Separator Class
The JPopupMenu class maintains its own separator to permit a custom look and feel for the separator
when it's on a JPopupMenu . This custom separator is an inner class to the JPopupMenu .
When you call the addSeparator() of JPopupMenu , an instance of this class is automatically
created and added to the pop-up menu. In addition, you can create this separator by calling its
no-argument constructor:
JSeparator popupSeparator = new JPopupMenu.Separator();
Both methods create a horizontal separator.
Note If you want to change the orientation of the separator, you must call the setOrientation()
method inherited from JSeparator with an argument of JPopupMenu.Separator.VERTICAL . However,
having a vertical separator on a pop-up menu is inappropriate.
A Complete Pop-Up Menu Usage Example
The program in Listing 6-3 puts together all the pieces of using a JPopupMenu , including listening
for selection of all the items on the menu, as well as listening for when it's displayed. The output for
the program is shown in Figure 6-7, with the pop-up visible.
Figure 6-7. JPopupMenu usage example output
Listing 6-3. PopupSample Class Definition
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class PopupSample {
 
Search WWH ::




Custom Search