Popmenu Problem

N

news

Hi All

I have created a JPopupMenu to popup at right mouse click on JTextPane. The
JPopupMenu has JCheckBoxMenuItem as its components. My problem is that the
popup menu is not showing up over the JTextPane. I am getting its view only
on click at the right end side of the pane. Click on other areas of the pane
is not showing the popup. It seems to be hidden under the pane.I tried
JPopupMenu.setLightweightpropertyEnabled(false), but even then i am not
getting it on top. Pls. do give me a solution.

Thanks in Advance.



Bye

Jimmy
 
R

Roedy Green

Click on other areas of the pane
is not showing the popup.

If indeed the popup in hiding underneath this won't help. However, if
it is simply not showing up trapping the click in three places may
help:

private void hookRightClickListener()
{
MouseListener newRightClickListener = new MouseAdapter()
{
/**
* Invoked when a mouse button has been pressed on node in
the Jtree
*/
public void mousePressed( MouseEvent e )
{
handleRightClick( e );
}
/**
* Invoked when a mouse button has been released on node in
the Jtree
*/
public void mouseReleased( MouseEvent e )
{
handleRightClick( e );
}
/**

* Invoked when a mouse button has been clicked on node in the
Jtree
*/
public void mouseClickedd( MouseEvent e )
{
handleRightClick( e );
}
}; // end anonymous MouseAdapter

// attach the MouseAdapter to the jtree
jtree.addMouseListener( newRightClickListener );
} // end hookRightClickListener

private void handleRightClick( MouseEvent e )
{

// if not considered a popup trigger, e.g. right click, ignore
it
if ( ! e.isPopupTrigger() )
{
return;
}
...
rootpopup.show( e.getComponent(), e.getX(), e.getY() );
}
 
?

=?ISO-8859-1?Q?Daniel_Sj=F6blom?=

news said:
Hi All

I have created a JPopupMenu to popup at right mouse click on JTextPane. The
JPopupMenu has JCheckBoxMenuItem as its components. My problem is that the
popup menu is not showing up over the JTextPane. I am getting its view only
on click at the right end side of the pane. Click on other areas of the pane
is not showing the popup. It seems to be hidden under the pane.I tried
JPopupMenu.setLightweightpropertyEnabled(false), but even then i am not
getting it on top. Pls. do give me a solution.

My guess is that the popupmenu appears in the upper left corner. Try
this in your mouselisteners mouseclicked method, where menu is the popup
menu, and thePane is your JTextPane:

if (e.getButton() == MouseEvent.BUTTON3) {
Point p = e.getPoint();
menu.show(thePane, p.x, p.y);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top