Catching mouse click on an irrigular shape image

Is it possible to catch the mouse click on an irrigular shape image on a JPanel? Can I simply attach a mouse listener to the image?

Hi,
you should use a mouseListener, and test the coordinates of the click in the mouseClicked() method, then you can use the inside() method of the Shape to see if the click occured in the shape.
Hope this will help,
Regards.

Similar Messages

  • Onclick javascript, catching mouse clicks

    Hello Forum,
    I have a page, let's say "page 1" with an interactive report and a column link.
    After a onclick event a page submit will be fired and i will be redirect to a new page, let's say "page 2".
    When i click now a second time at the column link on "page 1" (not a ondblclick event), before the page branches to "page 2", i will get an error.
    This is because there is a unique constraint violation with the building of collections on "page 2".
    As work around, i have the following idea but no solution for this idea.
    If someone clicks more than once, i want to catch every mouse-click on this column link as "void(0)" means "do nothing".
    In summary:
    the first mouse-click should be ok, the second, third, etc should do nothing.
    I guess ondblclick event is not a the right way to handle this issue.
    Because when someone clicks and he will wait for two seconds and then he clicks again before the page is branching,
    then we don't have a dbclick event, but the error is still coming.
    Does anybody have an idea to realize this task.
    Regards Stefan

    You should be using the nice existing apex properties
    See this http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21674/bldr_pg_edit_att.htm#HTMDB25159

  • Capture right mouse click in image

    I would like to capture a right mouse click while pointing into am image window.
    So far I've come only to the possibilty to capture events that originate somehow with the left mouse click.
    Or
    Are specific to the front panel of the currently active VI
    Or
    Detect whether at the time of calling a subVI the button is down or up, with all the usual hazzel of detecting the transition (plus the necessity of depending on MS Driect X).
    What I would like to have is a signal that describes the right click in an image window.
    Thanks for any ideas
    Gabi
    7.1 -- 2013
    CLA

    Hi,
    If you use LV7, you can use the event structure. Add an event or filter
    event "Mouse down" for the picture. The "button" value indicates 2 for the
    right button, 1 for the left.
    Regards,
    Wiebe.
    the picture control has a property "Mouse". This is a cluster, that includes
    "Gabriela Tillmann" wrote in message
    news:[email protected]..
    > I would like to capture a right mouse click while pointing into am
    > image window.
    > So far I've come only to the possibilty to capture events that
    > originate somehow with the left mouse click.
    > Or
    > Are specific to the front panel of the currently active VI
    > Or
    > Detect whether at the time of calling a subVI the button is down or
    > up, with all the usual hazzel of det
    ecting the transition (plus the
    > necessity of depending on MS Driect X).
    >
    > What I would like to have is a signal that describes the right click
    > in an image window.
    >
    > Thanks for any ideas
    > Gabi

  • Mouse clicks inside image in applet

    How can I respond to mouse clicks inside particular regions in an image loaded as part of an applet in a browser? ie, I want to send these clicks onto the server for the server to handle it and the server should change the image according to the mouse clicks.
    Thanks,

    /*  <applet code="ImageMouse" width="400" height="400"></applet>
    *  use: >appletviewer ImageMouse.java
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import java.net.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class ImageMouse extends JApplet
        JLabel label;
        public void init()
            ImageMousePanel panel = new ImageMousePanel();
            ImageMouser mouser = new ImageMouser(panel, this);
            panel.addMouseMotionListener(mouser);
            getContentPane().add(panel);
            getContentPane().add(getLabel(), "South");
        private JLabel getLabel()
            label = new JLabel(" ");
            label.setHorizontalAlignment(JLabel.CENTER);
            label.setBorder(BorderFactory.createTitledBorder("image coordinates"));
            Dimension d = label.getPreferredSize();
            d.height = 35;
            label.setPreferredSize(d);
            return label;
        public static void main(String[] args)
            JApplet applet = new ImageMouse();
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(applet);
            f.setSize(400,400);
            f.setLocation(200,200);
            applet.init();
            f.setVisible(true);
    class ImageMousePanel extends JPanel
        BufferedImage image;
        Rectangle r;
        public ImageMousePanel()
            loadImage();
            r = new Rectangle(getPreferredSize());
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            int w = getWidth();
            int h = getHeight();
            int imageWidth = image.getWidth();
            int imageHeight = image.getHeight();
            r.x = (w - imageWidth)/2;
            r.y = (h - imageHeight)/2;
            g2.drawImage(image, r.x, r.y, this);
            //g2.setPaint(Color.red);
            //g2.draw(r);
        public Dimension getPreferredSize()
            return new Dimension(image.getWidth(), image.getHeight());
        private void loadImage()
            String s = "images/greathornedowl.jpg";
            try
                URL url = getClass().getResource(s);
                image = ImageIO.read(url);
            catch(MalformedURLException mue)
                System.err.println("url: " + mue.getMessage());
            catch(IOException ioe)
                System.err.println("read: " + ioe.getMessage());
    class ImageMouser extends MouseMotionAdapter
        ImageMousePanel panel;
        ImageMouse applet;
        boolean outsideImage;
        public ImageMouser(ImageMousePanel imp, ImageMouse applet)
            panel = imp;
            this.applet = applet;
            outsideImage = true;
        public void mouseMoved(MouseEvent e)
            Point p = e.getPoint();
            if(panel.r.contains(p))
                int x = p.x - panel.r.x;
                int y = p.y - panel.r.y;
                applet.label.setText("x = " + x + "  y = " + y);
                if(outsideImage)
                    outsideImage = false;
            else if(!outsideImage)
                outsideImage = true;
                applet.label.setText("outside image");
    }

  • Mouse clicks on shapes drawn on canvas

    I'm having some trouble adding a mouseListener to a shape I've drawn on a canvas.
    I'm drawing a circle using g.drawOval() and then filling it in with the g.fillOval().
    The thing is I want the circle to be sensitive to mouse clicks on it, I'm trying to write the classic dots and boxes game, so I can draw a line from it to the
    next circle (dot) clicked.
    Unfortunately, the circle is not picking up on the mouseClicked event, I'm pretty sure my dotActions class works because I used it on another class which extends JLabel and it works fine, that is when the label is clicked the program exits, but when I add it to the Dots class it doesn't pick up on any mouse events.
    Here is my code, any help would be appreciated, thanks.
    public class Dots extends Canvas {
    public Dots(gameBoard gb, Graphics g, int x, int y, int hspace, int vspace){
    g.drawOval(x, y, 10, 10);
    g.fillOval(x, y, 10, 10);
    dotActions da = new dotActions(this);
    addMouseListener(da);
    public class dotActions implements MouseListener{
    public void mouseClicked(MouseEvent e){
    //this is a test to see if the mouse event is picked up
    System.exit(0);
    public void mouseEntered(MouseEvent e)
    public void mouseExited(MouseEvent e)
    public void mousePressed(MouseEvent e)
    public void mouseReleased(MouseEvent e)
    }

    Create a shape and add the listener to that as well as drawing to the screen.
    Or what I did was to save all the shapes and then test the mouse point to see if current mouse point was inside any. In my case I am using it to provide context sensitive help
    MArk
    * handle context sensitive tooltips - replaces default java
    * routine with our own which is context sensitive
    public String getToolTipText(MouseEvent e)
    Point raw_p = e.getPoint();
    //convert to our co-ords
    Point p = new Point(screenToScaledCoordsX((int) raw_p.getX()),
    screenToScaledCoordsY((int) raw_p.getY()));
    String tip = null;
    //check any tooltips to see if match found
    if (number_of_tooltips > 0)
    //check each object and get master tooltip text if inside rectangle if on
    //same page - go through all as text objects added before titles which will then be picked up
    for (int i = 0; i < number_of_tooltips; i++)
    if ((tool_tip_page[i] == last_page_id) &&
    (tool_tip_rectangle.contains(p)))
    tip = tool_tip_text[i];
    //return default or ours
    return tip;

  • Figuring out where a mouse click is under an image

    I want to create a JFrame (or JPanel) where the whole area is one big gif (or icon etc) and I want to make some areas of this panel react to mouse clicks and other areas display messages.
    There are two ways that I can think of doing this.
    The first is that I figure out the x and y coordinates of each area and check to see if each mouse click is within that area.
    The second way is to see if I can figure out how to put something like transparent JButtons over the areas that I want to accept mouse clicks (all the areas will be rectangular) and just do what JButtons do normally.
    The second way sounds easier but I don't know how to do that.
    Does anyone have opinions on which way I should do it?
    Thanks

    To me the first method sounds eaiser.
    A third possible idea? Add a bunch of JPanels to the frame and have split the image into several pieces that are painted by each JPanel. Then use a mouse listener to detect clicks. (Seems easier than trying to make JButton transparent and placing it at the correct point).

  • Using mouse click to return image coordinates.

    Ok so I've been trying to figure out how to do this and it seems very complicated for something that really seems straightforward.
    Anyway. I have a camera that updates an image object on the front panel using a while loop. I have another image object that is updated with a still image when the "snap" button is pressed. Now what I want to do is to click on a point in the snapped image and have the VI return the coordinates of that pixel in the image coordinate frame.
    What I've got so far is an event structure in the while loop with the following to occur in the event "image object -> mouse down":
    Server reference (reference to the image object) -> Property node (last mouse position) -> output screen coordinates.
    I've got two errors that don't make a whole lot of sense to me (I haven't worked with event structures before): "event data node contains unwired or bad terminal" and "event structure one or more event cases have no events defined". This second one seems strange since I don't actually want anything to happen if there's no mouse click. The first one seems to refer to the element box on the left hand side of the event structure.
    The above is my lastest attmpt at sorting this problem and as far as I can see it should work. whatever about the errors, am I even taking the right approach with this? I'd have thought image cordinates would be a common enough thing but search the boards here, it would appear not...
    Kinda stumped here. Any help is much appreciated.
    Message Edited by RoBoTzRaWsUm on 04-14-2009 08:34 AM
    Solved!
    Go to Solution.

    Hello RoBoTzRaWsUm,
    I have taken a look at your VI, which has been taking a correct approach to the data you are looking for.  As you are using and event structure, you should be looking for an event to occur.  When using a Property Node, you are trying read an attribute of a control.  However, in an Event Structure, I believe you should be using an Invoke Node.  An Invoke Node allows your to read an event or write a method with the Control Class in LabVIEW. 
    1. Place down and Invoke Node from the Functions Palette in 'Programming'->'Application Control'
    2. Wire your Image Control reference to it
    3. Click Method, and select 'Get Last Event'
    4. Right click on 'Which Events' and 'Create Constant'.  Make the constant '1' in the array
    5. Read the 'Coordinates' Cluster from the left hand side of the Event Case by right clicking  and 'Create Indicator'
    You will find a piece of example code attached.
    Regards
    George T.
    Applications Engineering Specialist
    National Instruments UK and Ireland
    Attachments:
    UKSupportMouseClick.vi ‏39 KB

  • Inserting an Image on mouse clicked HELP

    Hi.
    I', trying to make a Tic tac toe game(if you do not understand please run this programme).
    The thing I want to happen is:
    the user clicks over a "sqare" and when mouse is released the image (X or O) appears on that position.
    I can't get my programme to do this.
    I'm using the MouseListener Interface to implement the mouse events, but when, for example, I click on one square no image is loaded on that position. what can I do?
    Here's my code.
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.*;
    public class Gato extends JFrame implements MouseListener{
         Container content = getContentPane();
         JTextArea texto = new JTextArea(1,150);
         Graphics2D g2d;
         Image cruz = Toolkit.getDefaultToolkit().getImage("cruz.gif");
         Image bola = Toolkit.getDefaultToolkit().getImage("bola.gif");
         public static void main(String [] coms){
              new Gato();
         public Gato(){
              content.add(texto, BorderLayout.SOUTH);
    setSize(300,300);
    setVisible(true);
    setResizable(false);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    addMouseListener(this);
         public void paint(Graphics g){
              g2d = (Graphics2D)g;
              g2d.draw3DRect(100,50,1,200,true);
              g2d.draw3DRect(175,50,1,200,true);
              g2d.draw3DRect(35,111,200,1,true);
              g2d.draw3DRect(35,177,200,1,true);
              int x = 3;
              int y = 25;
              g2d.drawImage(cruz, x, y, this);
              x = 260;
              g2d.drawImage(bola, x, y, this);
         public void pon(int x, int y){
              g2d.drawImage(cruz, x, y, this);
         public void mousePressed(MouseEvent e){}
         public void mouseClicked(MouseEvent e){}
         public void mouseReleased(MouseEvent e){
              texto.append(" " + e.getX());
    pon(e.getX(),e.getY());
         public void mouseEntered(MouseEvent e){}
         public void mouseExited(MouseEvent e){}
    }

    Look at this:
    import java.awt.*;
    import java.awt.event.*;
    import java.math.*;
    public class TicTac extends Frame implements ActionListener
         Button   bx[]  = new Button[9];
         int      used;
         Font     f1    = new Font("System " , 1, 28);
         MenuItem ng    = new MenuItem("New Game");
    public TicTac() 
         super(" TicTacTo ");   
         setLayout(new GridLayout(3,3));
         addWindowListener(new WindowAdapter()
         {     public void windowClosing(WindowEvent ev)
              {     dispose();
                   System.exit(0);
         setBounds(60,60,159,179);
         for (int b = 0; b < bx.length; b++)
              bx[b] = new Button("");
              bx.setFont(f1);
              bx[b].setSize(50,50);
    bx[b].addActionListener(this);
         add(bx[b]);
         MenuBar mb = new MenuBar();
         Menu mm = new Menu("Option");
         ng.addActionListener(this);
         mb.add(mm);
         mm.add(ng);
         setMenuBar(mb);
         newboard();
         setVisible(true);
    public void newboard()
         for (int b = 0; b < bx.length; b++)
              bx[b].setLabel(".");
              bx[b].setEnabled(true);
         used = 0;
    public void actionPerformed(ActionEvent be)
         if (be.getSource() == ng)
              newboard();
              return;
         Button but = (Button)be.getSource();
         but.setLabel("X");
         but.setEnabled(false);
         used++;
         if (used != bx.length) Oplay();
    public synchronized void Oplay()
         int n = (int)(Math.random()*9);
         while (!bx[n].isEnabled()) n = (int)(Math.random()*9);
         bx[n].setLabel("O");
         bx[n].setEnabled(false);
         used++;
    public static void main (String[] args)
         new TicTac();

  • Getting mouse click coordinates with image button

    I'm using ADF Rich Client components in JDeveloper 11g Technology preview.
    I have to get the mouse click coordinates with an image button. In the page I put something like this:
    <af:commandButton text="commandButton1" icon="ambiente.jpg"
    actionListener="#{prova.listen}" action="#{prova.esegui}" />
    In the listener method of the managed bean I try to get the coordinates with this code:
    public void listen(ActionEvent e)
    FacesContext context = FacesContext.getCurrentInstance();
    String clientId = e.getComponent().getClientId(context);
    Map requestParams =
    context.getExternalContext().getRequestParameterMap();
    int x =
    new Integer((String) requestParams.get(clientId + ".x")).intValue();
    int y =
    new Integer((String) requestParams.get(clientId + ".y")).intValue();
    but it doesn't work. It seems that there aren't in the request the coordinates of the image point clicked. Is it true? How can I do that with ADF ?

    Hi,
    the mouse position is not part of the request parameters send. You will have to use client side JavaScript for this
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=windows-1252"/>
    <f:view>
    <af:document>
    <f:verbatim>
    <![CDATA[
    <script>
    function handleMouseCoordinates(event) {      
    alert("x: "+event.getPageX()+" y: "+event.getPageY());
    </script>
    ]]>
    </f:verbatim>
    <af:form>
    <af:commandButton text="My Click Button" icon="/images/jdev_cup.gif">
    <af:clientListener method="handleMouseCoordinates" type="click"/>
    </af:commandButton>
    </af:form>
    </af:document>
    </f:view>
    </jsp:root>
    Frank

  • My Apple TV 2 is slow when trying to move through different menu selections. It is like a slow computer trying to catch up to mouse clicks. It eventually remembers the buttons that were pushed on the remote, but it freezes and takes a minute to catch up.

    My Apple TV 2 is slow when trying to move through different menu selections. It is like a slow computer trying to catch up to mouse clicks. It eventually remembers the buttons that were pushed on the remote, but it freezes and takes a minute to catch up.

    I had something similar a couple of week ago, it would scroll then stop, scroll then stop.
    At some point the porblem went away.
    Try unpowering and restarting your AppleTV.  Rsetart iTunes too.

  • On right mouse click, there is no "save as" or "copy image" when I want to save a pictureon line. I have to go back to IE to access this option. Is this not available? Many thanks, Joy

    On right mouse click, there is no "save as" or "copy image" when I want to save a picture on line. I have to go back to IE to use this option. Is this not available? Many thanks, Joy
    There are so many occasions on line when I want to save an image that I can't believe I can't do so using Firefox, which I find so good in all other ways. I can Bookmark, save a page or send a link, but not take a simple copy image.

    Hi, Many thanks for replying, it's much appreciated. I started Firefox in safe mode and found I had the full right click menu on a pic on my home page. However, after moving around the web, I've found that the problem still occurs in eBay and it doesn't make any difference in safe mode. still no full menu. After returning to normal mode, I find that this still stands i.e. I do get the full menu on other sites but not in eBay. As I often want to save a pic in Ebay and can do so in IE, I'm baffled as to why this one site is giving problems. As this is where I've mostly been trying to save pics, I didn't realise that it was a "one site" problem and not applicable to everywhere else. If IE didn't work in this respect, I could blame the eBay site, but it does, so that just makes it more puzzling - and very annoying! I have tried accessing Ebay direct, rather than clicking on the toolbar, but this makes no difference. Any further thoughts would be much appreciated. Joy

  • "Image Save As" not aviable because Contect Menu on right mouse click

    Hi,
    I have a web report with a sheet and a graph. I would like to save the graph via right mouse click "Image Save As" but the IE menu is not available because the SAP menu is active on right mouse button. How can I activate the IE context menu?
    Regards, Thomas

    Hi,
    I need more information. At the moment my object looks like this one.
    <object>
             <param name="OWNER" value="SAP_BW"/>
             <param name="CMD" value="GET_ITEM"/>
             <param name="NAME" value="CHART_1"/>
             <param name="ITEM_ID" value="TEST"/>
             <param name="DATA_PROVIDER" value="DATAPROVIDER_2"/>
             <param name="TMP_CHART_DATA_HANDLE" value="IIP_0QWUSH2MVM2IIXXE5MMZ8LVHX"/>
             ITEM:            CHART_1
    </object>
    Regards, Thomas

  • Catch Keyevents inside mouse click

    hi,
    I want to catch diffrent key events(like shift +arrow key) inside mouse click how can i do that?                                                                                                                                                                                                               

    I have tryed it like this but i am getting same value of key. How can i get diffrent value for each key?
    (for example letter J or K should have diffrent key value when pressed)
    public void mouseClicked(MouseEvent me)
    /*me=new MouseEvent(me.getComponent(), int id, long when, ALT_DOWN_MASK, int x, int y,*/
         System.out.println("Key Event"+me.KEY_EVENT_MASK);
    System.out.println("me.getModifiers()"+me.getModifiers() );
         }

  • Firefox 9.0.1 with Flash player not catch keyboard event with mouse click.

    In a flash application, I need select mutil items using shite key and mouse click, it is not working. looks like firefox didn't pass the keyboard even alone with the click event. This happen on Window 7, IE and Chrome have no problem. only FF

    i have the same problem everytime i open a website with flashcontent firefox freezes and i have to kill the flash process to unfreeze the browser the only way i can see a youtube video is in html5 mode.
    Hardware
    Acer aspire 4553
    Turion X2 p520
    3gb of ddr3 ram
    Ati Mobility Radeon 4250

  • Trigger event on mouse click over image window

    How can I use an event structure to pick up on a mouse click on an IMAQ window in Labview. Specifically, I want to pick up a click with the 'select point' tool.

    To work in a Winddraw window, will not want to use the Event Structure, but instead the WindLastEvent. This will allow you to capture the events that occur in the Winddraw window. Attached are two examples, one I wrote using events so users can set up ROI's and the other is using events in LabVIEW with a picture control on the front panel so user can select an ROI.
    I hope this helps!
    Chris D
    Ni Application Engineer
    Attachments:
    Line_Profile_of_Live_Image.vi ‏145 KB
    ROI_from_Picture_Control_using_Events.vi ‏111 KB

Maybe you are looking for

  • Demo - SAP Strategy Management (SSM)

    Hey All, I`m in need a demo related with SAP Strategy Management that shows all the aplication, like core concepts and features. Can someone help me to get this? Best Regards, Bruno Heissler

  • Upgrade from Tiger 10.4.11 to Snow Leopard 10.6.5

    I have a MAC desktop with Tiger 10.4.11 and just recently bought another MAC desktop with Snow Leopard 10.6.5. I want to buy the Microsoft Office Home/Student 2011 for MAC 1 user with 3 license. Question: The older 10.4.11 will not support the 2011 e

  • Help me install adobe flash player on my mac ?

    Can you help me istall flash player on my Mac

  • Can't open pages documents after time machine restore.

    Hi, I had to do a restore of my document folder from time machine and now I can't open any pages documents. It just says not a valid format. It is only the pages documents that are affected. Not word documents. If I try to convert to plain text (or a

  • My PowerBook G4 won't boot up.

    I have a PowerBook G4, 17 inch, 80gb, 512 mb RAM (it's old :P). I dropped it about a foot, it landed flat on its bottom, and now it won't start up. It gets to the gray screen with the apple and the little spinning indication underneath, and stays the