Java - Insertar JPopupMenu al hacer click botonsecundario

 
Vista:

Insertar JPopupMenu al hacer click botonsecundario

Publicado por Diego (2 intervenciones) el 26/01/2008 13:51:52
Hola a todos!!

Me gustaria saber como puedo insertar un PopupMenu al hacer click con el boton secundario sobre un determinado elemento en una JToolBar. Tengo el siguiente codigo que en teoria se encarga de esto pero nunca entra en processMouseEvent() supongo que por algo de la herencia pero nose donde tengo el error :( Seria de gran ayuda si me dais algun consejo, Gracias!!!!!

/**
* Action class that shows the image specified in it's constructor.
*/
private class ThumbnailAction extends AbstractAction
{

/**
*The icon if the full image we want to display.
*/
private Icon displayPhoto;
private JPopupMenu jPopupMenu1 = new JPopupMenu();
private JPanel topPanel;
private JPopupMenu popupMenu;

/**
* @param Icon - The full size photo to show in the button.
* @param Icon - The thumbnail to show in the button.
* @param String - The descriptioon of the icon.
*/
public ThumbnailAction(Icon photo, Icon thumb, String desc){

topPanel = new JPanel();
topPanel.setLayout( null );
getContentPane().add( topPanel );

// Create some menu items for the popup
JMenuItem menuFileNew = new JMenuItem( "New" );
JMenuItem menuFileOpen = new JMenuItem( "Open..." );
JMenuItem menuFileSave = new JMenuItem( "Save" );
JMenuItem menuFileSaveAs = new JMenuItem( "Save As..." );
JMenuItem menuFileExit = new JMenuItem( "Exit" );

// Create a popup menu
popupMenu = new JPopupMenu( "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 );

// displayPhoto = photo;

// The short description becomes the tooltip of a button.
putValue(SHORT_DESCRIPTION, desc);

// The LARGE_ICON_KEY is the key for setting the
// icon when an Action is applied to a button.
putValue(LARGE_ICON_KEY, thumb);


}

public void processMouseEvent( MouseEvent event )
{

UserManager uM = new UserManager();
//the users that took anottations in the actualPDF are saved in usersThatTookAnots
Vector usersThatTookAnots = uM.usersThatTookAnots(users, actualPDF);

if( event.isPopupTrigger() )
{
System.out.println("is popup!");//popupMenu.show( event.getComponent(), event.getX(), event.getY() );
}

this.processMouseEvent( event );

}


/**
* Shows the full image in the main area and sets the application title.
*/

public void actionPerformed(ActionEvent e) {

System.out.println("hay evento");
photographLabel.setIcon(displayPhoto);
Executable ex = null;
/* try {
ex.openDocument("C:/Documents and Settings/Administrador/iText/src/com/lowagie/tools/PDF's/pdf3.pdf");
} catch (IOException exc) {
exc.printStackTrace();
}
*/
StringTokenizer st = new StringTokenizer (getValue(SHORT_DESCRIPTION).toString());
actualPDF =st.nextToken(". ");
actualPDF += ".pdf";
setTitle("Selected document: " + actualPDF);

}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder