Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Forums
Register
Login
Java
»
Swing / AWT / SWT
Using PopupMenu with awt components
Mala Gupta
,
Author
Jun 02, 2003 05:56:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
If I change the PopupMenu's to JPopupMenu's, Panel to JPanel and Frame to JFrame then the below code works, not otherwise. WHY??
import java.awt.*; import java.awt.event.*; import javax.swing.*; class PopupMenuExample1 extends Frame implementsActionListener { private PaneltopPanel; privatePopupMenupopupMenu; public PopupMenuExample1() { setTitle( "Popup Menu Application" ); setSize( 310, 130 ); setBackground( Color.gray ); topPanel = new Panel(); topPanel.setLayout( null ); //getContentPane().add( topPanel ); add( topPanel ); // Create some menu items for the popup MenuItem menuFileNew = new MenuItem( "New" ); MenuItem menuFileOpen = new MenuItem( "Open..." ); MenuItem menuFileSave = new MenuItem( "Save" ); MenuItem menuFileSaveAs = new MenuItem( "Save As..." ); MenuItem menuFileExit = new MenuItem( "Exit" ); // Create a popup menu popupMenu = new PopupMenu( "Menu" ); popupMenu.add( menuFileNew ); popupMenu.add( menuFileOpen ); popupMenu.add( menuFileSave ); popupMenu.add( menuFileSaveAs ); popupMenu.add( menuFileExit ); topPanel.add( popupMenu ); // Action and mouse listener support enableEvents( AWTEvent.MOUSE_EVENT_MASK ); menuFileNew.addActionListener( this ); menuFileOpen.addActionListener( this ); menuFileSave.addActionListener( this ); menuFileSaveAs.addActionListener( this ); menuFileExit.addActionListener( this ); } public void processMouseEvent( MouseEvent event ) { if( event.isPopupTrigger() ) { popupMenu.show( event.getComponent(), event.getX(), event.getY() ); } super.processMouseEvent( event ); } public void actionPerformed( ActionEvent event ) { // Add action handling code here System.out.println( event ); } public static void main( String args[] ) { // Create an instance of the test application PopupMenuExample1 mainFrame= new PopupMenuExample1(); mainFrame.setVisible( true ); } }
[ June 03, 2003: Message edited by: Cindy Glass ]
Cindy Glass
,
"The Hood"
staff
Jun 03, 2003 10:13:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
Moving to the Swing and AWT forum.
Post by:
autobot
Acetylsalicylic acid is aspirin. This could be handy too:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
This thread has been viewed 1316 times.
Similar Threads
PopupMenu in Menu?
two jpopupmenus associates with two differents components
How to make popup invisible
HOw to add menu to a button ?
System Tray - double click icon to set visible
More...
All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 20:28:16
.