Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 25th, 2003, 06:44 AM
Registered User
 
Join Date: Jul 2003
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ransomhmc
Default about JPopupMenu

i wrote a JPanel capable of drawing lines on it,
now i want to pop up a JPopupMenu when clicking MouseButton3,

here is my code:

import javax.swing.*;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.*;


public class ScribblePane1 extends JPanel
        implements MouseListener, MouseMotionListener {

    private int last_x,last_y;
    private JPopupMenu pop = new JPopupMenu();

    public ScribblePane1() {

        this.addMouseListener(this);
        this.addMouseMotionListener(this);
        setPreferredSize(new Dimension(300, 500));
        pop.add(new JMenuItem("test"));
    }

    //mouse events
    public void mouseClicked(MouseEvent e) {
    }

    public void mouseEntered(MouseEvent e) {
    }

    public void mouseExited(MouseEvent e) {
    }

    public void mousePressed(MouseEvent e) {
        maybePopup(e);
            last_x = e.getX();
            last_y = e.getY();
    }

    public void mouseReleased(MouseEvent e) {
        maybePopup(e);
    }

    public void maybePopup(MouseEvent e) {
       if (e.isPopupTrigger()) {
            pop.show((Component)e.getSource(), e.getX(),e.getY());
        }
    }
    //mouse motion events
    public void mouseDragged(MouseEvent e) {
            this.getGraphics().drawLine(last_x, last_y, e.getX(),e.getY());
            last_x = e.getX();
            last_y = e.getY();
      }

    public void mouseMoved(MouseEvent e) {
    }
}

but when pop.show() is invoked,
the lined drew already will be covered and disappear,
what's the problem? and what should i do to fix it?

sorry my english is not good,
hope you can understand what i want to say,
thanks all :)

Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off




All times are GMT -4. The time now is 07:08 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.