开发者

Java popup, Jpanel and PopupFactory - update x and y coordinates

I have a Jpanel, which I want to add a info popup on right click. So, the coordinates of the popup can change. However, when I add a popup in the paintComponent method, the application slows down considerab开发者_运维技巧ly.

I am using the following code to get an instance of the popup from the popupFactory in the paintComponent:

public void paintComponent(java.awt.Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g;

if(Show){
    popup = factory.getPopup(this, l, mouseX, mouseY); 
    popup.show();
}

l is a simple JLabel. Is there another way to add an info popup on right click on a Jpanel.

Cheers,

Slotishtype


Is there another way to add an info popup on right click on a Jpanel.

The normal way is to use a MouseListener and to listen for the right mouse click and then display the popup. The paintComponent() method has nothing to do with displaying popups, since the popup is not part of the component.


You should not be adding a popup every time the component is painted.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜