Change image on mouse event

I would like to have an image change when when the mouse is over an element any help is aprresiated
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.geom.*;
import java.io.*;
* @author  tom
public class CNP extends java.applet.Applet {
    File rcfile=null;
  java.io.BufferedReader br;
    Image img;
  int H;
  int W;
   Label labl(){
      img=getImage(getCodeBase(),"ide.gif");
    final Label label=new iLabel(img);
    Graphics gr=this.getGraphics();
label.paint(gr);
    label.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                label1MouseClicked(label,evt);
             public void mouseExited(java.awt.event.MouseEvent evt) {
                label1MouseExited(label,evt);
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                label1MouseEntered(label,evt);
    return label;   
String lbl[]={"a","B","Cc","dDd","E"};
    int i=0;
    /** Initialization method that will be called after the applet is loaded
     *  into the browser.
    public void init() {
         try{
  java.io.BufferedReader br= new BufferedReader(new FileReader(rcfile));
  catch(Exception e){e.printStackTrace();}
         setLayout(null);
       for(i=0;i!=lbl.length;i++){
       CreateButton(i);
   public void paint(Graphics g){
    g.setColor(new Color(33,88,216,255));
       g.fillOval(63, 63, 74, 74);
   int x[]={0,100};
       int y[]={0,100};
int R=75;
float dx;
float dy;
       int X=50;
       int Y=50;
       int Cx=100;
       int Cy=100;
       int n=lbl.length;
    void CreateButton(int i){
         Arc2D arc=new Arc2D.Double();
         int t=360/lbl.length;
  arc.setArcByCenter(Cx, Cy, R, 0, t*i, arc.OPEN);
  dx=Math.round(arc.getEndPoint().getX());
  X=Math.round(dx);
  dy=Math.round(arc.getEndPoint().getY());
  Y=Math.round(dy);
   Label l= labl();
    W=this.img.getWidth(null);
   H=this.img.getHeight(null);
if(Cx>X){X=X-W;}
  if(Cy>Y){Y=Y-H; }
   this.add(l);
   l.setBounds(X,Y,W,H);
    void label1MouseClicked(Label l1,MouseEvent evt){
    javax.swing.JOptionPane.showMessageDialog(null,l1.getText()+" ("+evt.getX()+","+evt.getY()+")","CNP",1);
    void label1MouseEntered(Label l1,MouseEvent evt){
     img=getImage(getCodeBase(), "ide_hover.gif");       
   l1=new CNP.iLabel(img);
    l1.paint(this.getGraphics());
    void label1MouseExited(Label l1,MouseEvent evt){
    javax.swing.JOptionPane.showMessageDialog(null,l1.getText()+" ("+evt.getX()+","+evt.getY()+")","CNP",1);
    class iLabel extends Label{
public Image image;
    iLabel(Image i){
    this.image=i;
public void setImage(Image i){
this.image=i;
public void paint(Graphics g){
super.paint(g);
g.clearRect(0, 0, image.getWidth(null), image.getHeight(null));
    g.drawImage(this.image,0,0,this);
}

i got it to work with
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.geom.*;
import java.io.*;
* @author  tom
public class CNP extends java.applet.Applet {
    File rcfile=null;
    java.io.BufferedReader br;
    Image img;
    int H;
    int W;
    Label labl(){
        img=getImage(getCodeBase(),"ide.gif");
        final iLabel label=new iLabel(img);
        Graphics gr=this.getGraphics();
        label.paint(gr);
        label.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                label1MouseClicked(label,evt);
            public void mouseExited(java.awt.event.MouseEvent evt) {
                label1MouseExited(label,evt);
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                label1MouseEntered(label,evt);
        return label;
    String lbl[]={"a","B","Cc","dDd","E"};
    int i=0;
    /** Initialization method that will be called after the applet is loaded
     *  into the browser.
    public void init() {
        try{
            java.io.BufferedReader br= new BufferedReader(new FileReader(rcfile));
        catch(Exception e){e.printStackTrace();}
        setLayout(null);
        for(i=0;i!=lbl.length;i++){
            CreateButton(i);  
    public void paint(Graphics g){
        g.setColor(new Color(33,88,216,255));
        g.fillOval(63, 63, 74, 74);  
    int x[]={0,100};
    int y[]={0,100};
    int R=75;
    float dx;
    float dy;
    int X=50;
    int Y=50;
    int Cx=100;
    int Cy=100;
    int n=lbl.length;
    void CreateButton(int i){
        Arc2D arc=new Arc2D.Double();
        int t=360/lbl.length;
        arc.setArcByCenter(Cx, Cy, R, 0, t*i, arc.OPEN);
        dx=Math.round(arc.getEndPoint().getX());
        X=Math.round(dx);
        dy=Math.round(arc.getEndPoint().getY());
        Y=Math.round(dy);
        Label l= labl();
        W=this.img.getWidth(null);
        H=this.img.getHeight(null);
        if(Cx>X){X=X-W;}
        if(Cy>Y){Y=Y-H; }
        this.add(l);
        l.setBounds(X,Y,W,H);   
    void label1MouseClicked(iLabel l1,MouseEvent evt){
        javax.swing.JOptionPane.showMessageDialog(null,l1.getText()+" ("+evt.getX()+","+evt.getY()+")","CNP",1);
    void label1MouseEntered(iLabel l1,MouseEvent evt){
        Graphics gr=this.getGraphics();
        img=getImage(getCodeBase(), "ide_hover.gif");
        Point p=l1.getLocation();
        l1.setCursor(new Cursor(Cursor.HAND_CURSOR));
        l1.setImage(img, p);
        l1.paint(gr);
    void label1MouseExited(iLabel l1,MouseEvent evt){
         Graphics gr=this.getGraphics();
        img=getImage(getCodeBase(), "ide.gif");
        Point p=l1.getLocation();
        l1.setImage(img, p);
        l1.paint(gr);
        this.repaint();
    class iLabel extends Label{
        public Image image;
        int ix=0;
        int iy=0;
        iLabel(Image i){
            this.image=i;
        public void setImage(Image i,Point p){
            this.image=i;
            this.ix=p.x;
            this.iy=p.y;
        public void paint(Graphics g){
            super.paint(g);
            g.clearRect(0, 0, image.getWidth(null), image.getHeight(null));
            g.drawImage(this.image,ix,iy,this);
}

Similar Messages

  • Trying to create a surface  with multiple images with mouse events

    novice programmer (for a applet program)
    hi trying to create a surface i.e jpanel, canvas, that allows multiple images to be created.
    Each object is to contain a image(icon) and a name associated with that particular image. Then each image+label has a mouse event that allows the item to be dragged around the screen.
    I have tried creating own class that contains a image and string but I having problems.
    I know i can create a labels with icons but having major problems adding mouse events to allow each newly created label object to moved by the users mouse?
    if any one has any tips of how to acheive this it would be much appreciated. Thanks in advance.
    fraser.

    This should set you on the right track:- import java.awt.*;
        import java.awt.event.*;
        import javax.swing.*;
        public class DragTwoSquares extends JApplet implements MouseListener, MouseMotionListener {  
           int x1, y1;   // Coords of top-left corner of the red square.
           int x2, y2;   // Coords of top-left corner of the blue square.
           /* Some variables used during dragging */
           boolean dragging;      // Set to true when a drag is in progress.
           boolean dragRedSquare; // True if red square is being dragged, false                              //    if blue square is being dragged.                            
           int offsetX, offsetY;  // Offset of mouse-click coordinates from
                                  //   top-left corner of the square that was                           //   clicked.
           JPanel drawSurface;    // This is the panel on which the actual
                                  // drawing is done.  It is used as the
                                  // content pane of the applet.  It actually                      // belongs to an anonymous class which is
                                  // defined in place in the init() method.
            public void init() {
                 // Initialize the applet by putting the squares in a
                 // starting position and creating the drawing surface
                 // and installing it as the content pane of the applet.
              x1 = 10;  // Set up initial positions of the squares.
              y1 = 10;
              x2 = 50;
              y2 = 10;
              drawSurface = new JPanel() {
                        // This anonymous inner class defines the drawing
                        // surface for the applet.
                    public void paintComponent(Graphics g) {
                           // Draw the two squares and a black frame
                           // around the panel.
                       super.paintComponent(g);  // Fill with background color.
                       g.setColor(Color.red);
                       g.fillRect(x1, y1, 30, 30);
                       g.setColor(Color.blue);
                       g.fillRect(x2, y2, 30, 30);
                       g.setColor(Color.black);
                       g.drawRect(0,0,getSize().width-1,getSize().height-1);
              drawSurface.setBackground(Color.white);
              drawSurface.addMouseListener(this);
              drawSurface.addMouseMotionListener(this);
              setContentPane(drawSurface);
           } // end init();
           public void mousePressed(MouseEvent evt) {
                  // Respond when the user presses the mouse on the panel.
                  // Check which square the user clicked, if any, and start
                  // dragging that square.
              if (dragging)  // Exit if a drag is already in progress.
                 return;           
              int x = evt.getX();  // Location where user clicked.
              int y = evt.getY();        
              if (x >= x2 && x < x2+30 && y >= y2 && y < y2+30) {
                     // It's the blue square (which should be checked first,
                     // since it's in front of the red square.)
                 dragging = true;
                 dragRedSquare = false;
                 offsetX = x - x2;  // Distance from corner of square to (x,y).
                 offsetY = y - y2;
              else if (x >= x1 && x < x1+30 && y >= y1 && y < y1+30) {
                     // It's the red square.
                 dragging = true;
                 dragRedSquare = true;
                 offsetX = x - x1;  // Distance from corner of square to (x,y).
                 offsetY = y - y1;
           public void mouseReleased(MouseEvent evt) {
                  // Dragging stops when user releases the mouse button.
               dragging = false;
           public void mouseDragged(MouseEvent evt) {
                   // Respond when the user drags the mouse.  If a square is
                   // not being dragged, then exit. Otherwise, change the position
                   // of the square that is being dragged to match the position
                   // of the mouse.  Note that the corner of the square is placed
                   // in the same position with respect to the mouse that it had
                   // when the user started dragging it.
               if (dragging == false)
                 return;
               int x = evt.getX();
               int y = evt.getY();
               if (dragRedSquare) {  // Move the red square.
                  x1 = x - offsetX;
                  y1 = y - offsetY;
               else {   // Move the blue square.
                  x2 = x - offsetX;
                  y2 = y - offsetY;
               drawSurface.repaint();
           public void mouseMoved(MouseEvent evt) { }
           public void mouseClicked(MouseEvent evt) { }
           public void mouseEntered(MouseEvent evt) { }
           public void mouseExited(MouseEvent evt) { }  
        } // end class

  • Change images on mouse click

    hi,
    cud anyone help me to change image in a JPanel in JFrame.On MouseClick event. the image should in an panel on mouseclick,plz explain with example source code.
    thank u

    I dvlp MyPanel to accept 2 image file name.
    You can easy change to accept Image instead of file name.
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class Test {
    public static void main(String args[]) {
    JFrame f = new JFrame("Test");
    MyPanel p = new MyPanel("YourFirstImage.gif", "YourSecondImage.gif");
    p.add(new JButton("Click on Panel (not Button)"));
    f.setContentPane(p);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
    class MyPanel extends JPanel implements MouseListener {
    Image image, image1, image2;
    public MyPanel(String image1Name, String image2Name) {
    //load image
    try {
    image1 = getToolkit().getImage(getClass().getResource(image1Name));
    image2 = getToolkit().getImage(getClass().getResource(image2Name));
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image1, 0);
    mt.addImage(image2, 0);
    mt.waitForAll();
    } catch (Exception e) { e.printStackTrace(); }
    this.image1 = image1;
    this.image2 = image2;
    this.image = image1;
    this.addMouseListener(this);
    public void paintComponent(Graphics g) {
    g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);
    public void mouseClicked(MouseEvent e){
    image = (image == image1) ? image2 : image1; // switch between image1, image2
    repaint();
    public Dimension getPreferredSize() {
    Dimension dim = super.getPreferredSize();
    int w = Math.max(image1.getWidth(this), image2.getWidth(this));
    int h = Math.max(image1.getHeight(this), image2.getHeight(this));
    w = Math.max(dim.width, w);
    h = Math.max(dim.height, h);
    return new Dimension(w, h);
    public void mouseEntered(MouseEvent e) {}
    public void mouseExited(MouseEvent e) {}
    public void mousePressed(MouseEvent e) {}
    public void mouseReleased(MouseEvent e) {}

  • I need to set an image - on mouse event it will be moved across a drawing

    like a stickers

    Place the image in a movieclip or sprite and assign it an instance name so that you can assign an MouseEvent listener to it.  Make the event handler function process moving the movieclip/sprite.

  • Can i capture the the mouse events

    i am writting application in which i have to send the screen image to client as well as mouse events and keyboard events. i am successfull in doing screen image but mouse events are not traped
    please send me any suggestion about how i will do it.
    [email protected]

    Have you tried to implement MouseListener?

  • Image control mouse move event updates

    I would like to drag the ROI around in the Image control (holding down the left mouse button) and continually read out the ROI coordinates. I can't find a way to do this: the mouse move event does not seem to fire if I hold the left mouse button down. I assumed that I would have
    1. Mouse down when I click and hold.
    2. Mouse move when I move the ROI around.
    3. Mouse up when I release the left mouse button.
    This does not seem to be the case.
    I've done a simple workaround which is
    1. Use the key up event to check that the space bar has been pressed.
    2. Use this to toggle a "lock" boolean which locks the target to the mouse coordinates.
    3. Use the mouse move event to return the Image Control Mouse Coordinates property.
    4. Unlcok the target from the mouse coordinates by pressing the space bar again.
    This kind of works, but it is much less intuitive than the standard windows "click and drag".
    Any comments appreciated.
    Thanks.
    PS The Image Control is excellent, it has saved me lots of development time. Also, the ROI tools are hugely useful.

    If you filter the mouse down event (MOUSE DOWN?) then the coordinated are always returned on mouse move event weather the mouse is down or not.  I did get the coordinates when the left button was down anyway it was just when the right button was down which the move event was not handled (due to the popup menu consuming the event first?)  I thing there is a good way to do this with dynamic event registration, and NI has a similar example of drag and drop of controls, but I am not at my LV machine to look for it right now.  If I am wrong I am sorry it is early and my coffee is not brewed yet.
    Paul
    Paul Falkenstein
    Coleman Technologies Inc.
    CLA, CPI, AIA-Vision
    Labview 4.0- 2013, RT, Vision, FPGA

  • Change image resolution using image events

    Does anyone have an applescript to change image resolution using image events in OSX? I want to optimize my images for iWeb. I want to use a shell script in an applescript as a droplet or as a service in Automator. I'd like to leave the original intact.

    No? Oh...ok den. No Applescripts at all.

  • Applescript to change image resolution using image events

    Does anyone have an applescript to change image resolution using image events in OSX? I want to optimize my images for iWeb. I want to use a shell script in an applescript as a droplet or as a service in Automator. I'd like to leave the original intact.

    For what type of use in iWeb are these photos intended? If it's for adding to a page (not a photo or album page) iWeb does a great job of optimizing. See my post in this topic: Re: Photo Resolution in iWeb.
    You can optimize an entire site with an application like Web Site Maestro. It can reduce the site's size by up to 49%. Here's the settings available for the optimization:
    Click to view full size
    It's very effective.
    OT

  • Changing image by mouseclick

    How do I change my image to another one on mouse click ? Thanks in advance

    I may add that there a 2 ways of changing images. If all your images are the same size then place 1 on the stage and change from div to img. then you can use:
    Here I assume you go through an array on your click event:
    sym.$('imageName").attr("scr","images/"+ arrayName[i]+".jpg");
    and as Vivekuma said if you have images that are different size - use an empty did and change the background.
    sym.$("image").attr("src", "images/image" + arrayName[i]+ ".png");
    I will choose whatever makes more sense in my project.

  • Thumbnail images in the event browser

    After about 20 minutes on FCPX the thumbnail images in the event browser randomaly disappear. If I move the scrubber bar over the blank thumbnail the image reappears but only for as long as I linger on the thumbnail. The audio track remains visible all the time. Changing the view or the scale doesn't help. It's difficult to find clips, as you can imagine. Anyone else having this problem? 

    Thanks Russ. After returning to original layout the problem subsided but returned after a longer time period (about two hours). I was just working (on a different project) and suddenly %90 of the thumbnails turned blue. I could still see the audio information but the pictures vanished. The picture returns when the scrubbing bar hovers over the thumbnail then disappears again when I take the bar away. This is incredibly frustrating. Could it be because I'm using a thunderboldt display off of my Mac Book Pro? Both are less than 1 year old and the Pro is (was) top of the line at the time. Blind as a bat. 

  • Changing Images at Runtime...it's sending me nuts (I'm a newbie, go easy)

    Hi all,
    I am trying change images at runtime and quite frankly it's driving me nuts. I'm pretty new to Java and don't understand some of the principles but I'm trying. I have this code below, that loads up a few images. I want to be able to change some/all of these images either on a timed even or on a button press, but all the things I've tried don't work. Can someone offer me some help....thanks in advance
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class bc extends JFrame implements ActionListener {
         public static void main(String[] args) {new bc();}
         bc() {
              //setUndecorated(true); // - this removed the titlebar!
                    setTitle("BC...");
              setSize(350,125);
              setResizable(false);
              setLocation(50,50);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              setBackground(new Color(0,0,0));
              getContentPane().setBackground(new Color(255,255,255));
              JPanel hours = new JPanel();
              hours.setLayout(new GridLayout(4,2));
              hours.add(hour14);
              hours.add(hour24);
              hours.add(hour13);
              hours.add(hour23);
              hours.add(hour12);
              hours.add(hour22);
              hours.add(hour11);
              hours.add(hour21);
              JPanel mins = new JPanel();
              mins.setLayout(new GridLayout(4,2));
              mins.add(min14);
              mins.add(min24);
              mins.add(min13);
              mins.add(min23);
              mins.add(min12);
              mins.add(min22);
              mins.add(min11);
              mins.add(min21);
              JPanel secs = new JPanel();
              secs.setLayout(new GridLayout(4,2));
              secs.add(sec14);
              secs.add(sec24);
              secs.add(sec13);
              secs.add(sec23);
              secs.add(sec12);
              secs.add(sec22);
              secs.add(sec11);
              secs.add(sec21);
              JPanel helptext = new JPanel();
              helptext.setLayout(new GridLayout(4,2));
              helptext.add(new JLabel("8"));
              helptext.add(new JLabel("4"));
              helptext.add(new JLabel("2"));
              helptext.add(new JLabel("1"));
    //add action listenters
              changeImg.addActionListener(this);
              JPanel cp = new JPanel();
              cp.setLayout(new GridLayout(1,6));
              cp.setBackground(new Color(255,255,255));
              cp.add(hours);
              cp.add(mins);
              cp.add(secs);
              cp.add(helptext);
              cp.add(changeImg);
              setContentPane(cp);
              setVisible(true);
         public void actionPerformed(ActionEvent ae) {
              hour11.PaintOff(1);
              //JOptionPane.showMessageDialog(this, "changed");
              repaint();
    JPanel hour11 = new PaintOff(0);
    JPanel hour12 = new PaintOff(0);
    JPanel hour13 = new PaintBlank();
    JPanel hour14 = new PaintBlank();
    JPanel hour21 = new PaintOff(0);
    JPanel hour22 = new PaintOff(0);
    JPanel hour23 = new PaintBlank();
    JPanel hour24 = new PaintBlank();
    JPanel min11 = new PaintOff(0);
    JPanel min12 = new PaintOff(0);
    JPanel min13 = new PaintOff(0);
    JPanel min14 = new PaintOff(0);
    JPanel min21 = new PaintOff(0);
    JPanel min22 = new PaintOff(0);
    JPanel min23 = new PaintOff(0);
    JPanel min24 = new PaintOff(0);
    JPanel sec11 = new PaintOff(0);
    JPanel sec12 = new PaintOff(0);
    JPanel sec13 = new PaintOff(0);
    JPanel sec14 = new PaintOff(0);
    JPanel sec21 = new PaintOff(0);
    JPanel sec22 = new PaintOff(0);
    JPanel sec23 = new PaintOff(0);
    JPanel sec24 = new PaintOff(0);
    JButton changeImg = new JButton("change");
    }///---------This is my PaintOff class ---------------\\\
    import javax.swing.*;
    import java.awt.*;
    import java.awt.Image.*;
    public class PaintOff extends JPanel {
    Toolkit tk = Toolkit.getDefaultToolkit();
    public Image imgOff = tk.getImage("off.jpg");
    public Image imgOn = tk.getImage("on.jpg");
    public Image paintMe = tk.getImage("off.jpg");
         PaintOff(int a) {
              if(a == 1) {
                   vOn();
              } else {
                   vOff();
         public void vOn() {
            paintMe = imgOn;
         //JOptionPane.showMessageDialog(new bc(), "shown");
         public void vOff() {
            paintMe = imgOff;
         public void paintComponent(Graphics g) {
              g.drawImage(paintMe,0,0,this);
    }PaintBlank class is not included here, it's basically just the same as PaintOff but only has one image inside.
    When I try and compile this code, I get
    C:\jdk1.4\bin\bclock>javac bc.java
    bc.java:79: cannot resolve symbol
    symbol : method PaintOff (int)
    location: class javax.swing.JPanel
    hour11.PaintOff(1);
    ^
    1 error
    I don't understand this either, I've tried replacing "PaintOff(1)" with "vOn()" but I get the same error. This is baffling to be, as I thought that the hour11 would have access to all the methods inside the PaintOff class?
    Anyway, thanks for any help you guys give me!
    Cheers
    //Chris.

    Hi!
    Your problem is that you've used a widening conversion to convert from PaintOff to a JPanel. JPanel has no such method, and so the compiler is complaining that it can't find it.
    e.g
    public class NoCompile{
         public static void main(String args[]){
              One one = new Two();
              one.methTwo();
    public class Two extends One{
         public Two(){}
         public void methTwo(){
            System.out.println("Executed 2");
    public class One{
         public One(){}
         public void meth1(){}
    } will give you the same sort of error message. To make the compiler happy, use a cast.
    Now this will compile and gives the right result.
    public class NoCompile{
         public static void main(String args[]){
              One one = new Two();
              ((Two)one).methTwo();
    }So in your case, you want to do
    ((PaintOff)hour11).vOn();
    Does that help?
    :) jen

  • Displaying dynamically changing image: a problem with JLabel.

    Hello! I use NetBeans 5.5 and I develop my GUI with Matisse. I'm rather a beginner in developing GUIs with this editor...
    I'd like to display a dynamically changing image. The idea is: GUI shows the image, that is modified as some computations run in a different thread. App will be run on a single machine.
    I'm trying to display the image as a label's icon. The problem is that my app's frame can be resized - and when it is, the label also resizes. When the label is resized, the image should also be resized - the image should always be of the same size as the label. The problem? I noticed, that it works only when I make my app's bigger. When I try to lower its dimensions, the label's dimensions remain the same. Why the label don't make its size smaller?
    My code works as follows: when app's main frame is resize, the panel (the one, that the label is placed in) is also resized. And, since the label is in the panel, it (should) also be resized. So I wrote all the resize-events handlers (therefore I know that the resize event is sent when my app's frame is resized, and when the panel is resized - but the label is resized only when it grows bigger). In this methods I modify the image displayed in the label (I resize the image).
    Or, perhaps, there is some other way to show a (dynamically changing) image with Swing... I chose JLabel, because I didn't want to write my own JComponent. JLabel can display image and that is all I need. The problem is: when the label grows bigger, I create a new, bigger image (icon). Why my label don't get smaller (the resize event isn't even sent)?

    There is no component that dynamically resizes an image. You need to create your own. Something like this:
    JComponent component = new JComponent()
         protected void paintComponent(Graphics g)
              //  Scale image to size of component
              g.drawImage(yourImage, 0, 0, getWidth(), getHeight(), null);
    };

  • How to catch the mouse event from the JTable cell of  the DefaultCellEditor

    Hi, my problem is:
    I have a JTable with the cells of DefaultCellEditor(JComboBox) and added the mouse listener to JTable. I can catch the mouse event from any editor cell when this cell didn't be focused. However, when I click the editor to select one JComboBox element, all the mouse events were intercepted by the editor.
    So, how can I catch the mouse event in this case? In other word, even if I do the operation over the editor, I also need to catch the cursor position.
    Any idea will be highly appreciated!
    Thanks in advance!

    Hi, bbritta,
    Thanks very much for your help. Really, your code could run well, but my case is to catch the JComboBox event. So, when I change the JTextField as JComboBox, it still fail to catch the event. The following is my code. Could you give me any other suggestion?
    Also, any one has a good idea for my problem? I look forward to the right solution to this problem.
    Thanks.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test3
    extends JFrame {
    // JTextField jtf = new JTextField();
    Object[] as = {"aa","bb","cc","dd"};
    JComboBox box = new JComboBox(as);
    public Test3() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = getContentPane();
    String[] head = {
    "One", "Two", "Three"};
    String[][] data = {
    "R1-C1", "R1-C2", "R1-C3"}
    "R2-C1", "R2-C2", "R2-C3"}
    JTable jt = new JTable(data, head);
    box.addMouseListener(new MouseAdapter() {
    // jtf.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e)
    System.out.println("-------------------JComboBox mouseclick....");
    jt.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e)
    System.out.println("-------------------JTable mouseclick....");
    // jt.setDefaultEditor(Object.class, new DefaultCellEditor(jtf));
    jt.setDefaultEditor(Object.class, new DefaultCellEditor(box));
    content.add(new JScrollPane(jt), BorderLayout.CENTER);
    setSize(300, 300);
    public static void main(String[] args) {
    new Test3().setVisible(true);
    }

  • Inappropriate mouse event coordinates in the WebKit of HTMLLoader/StageWebView

    Hi,
    We have a desktp application which incorporates an HTMLRichTextEditor (implemented in HTML/JS and loaded into AIR).
    We have run into a big problem with text selection though. It seems that the both the HTMLLoader and the StageWebView are passing wrong mouse coordinates to the WebKit when the cursor is outside of the component.
    I've created a sample application which uses mx:HTML (which is a wrapper of the HTMLLoader) and a WebView class (a wrapper aroun StageWebView reference to which is given here).
    The application is located here in Dropbox. The source code of the app is here.
    The app was built with Flex 4.6 and ran in AIR 3.7
    The sample app has a WebView which loads loremipsum and HTML loading some dummy local HTML page. The HTML page uses the JS->AIR bridge to report the mouseevents to a function in AIR. In the snapshot below the selection was started from the first row and then slowly continued to the left. As soon as it reaches the green area the selection changes unexpectably. As it can be seen in the bottom right -> the WebKit has received a mouse event with incorrect coordinates. The reported mouse coordinates seem to be the mouse coordinates within the green component and the selection behaves like that. If the mouse is moved to the blue - the selection changes again (according to the coordinates in the blue area).
    The component which uses the StageWebView behaves in absolutely the same way.
    I'd assume that I have to post a bug but I decided to post here at first.
    I've tried a few workarounds in order to stop and ongoing selection or to change it's behaviour but none of them with any relevant success. Even disabling mouse children for the entire application has no effect on the selection once it's started.
    Any help and/or comments would be much appreciated.
    Thanks !

    Thank you for the heads up.  Do you know if this is a recent change in behavior with AIR (ie. does this occur in previous versions)?  Regardless, could you please open a new bug report on this over at bugbase.adobe.com? 
    Once added, please post back with the URL so that others affected can add their comments and votes and I can follow up internally.
     

  • How can i highlight an image when mouse over an image in c#?

    I want to highlight an image when mouse goes there on image. The backcolor of image should change. Give a solution.

    Its for button. I need to highlight image. I have attached screen shot. I want to create like that in windows form.
    Hello,
    Based on my understanding, it just changes the background for that image to highlight them.
    So we could change the background for the control hosts these images, and in addition, the size mode should not be autosize, because we should keep some area to display the background.
    Regards,
    Carl
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

Maybe you are looking for

  • IPod and Windows Vista beta 2 X64

    Hi.. I've just installed the vista beta X64.. and iTunes don't work with it.. here's the solution: Buy Anapod explorer.. First download the latest update (now 28-06-06).. install it.. then install anapod.. Then it's working..

  • Questions on SCOM -SCVMM integration

    Hi All, I have some questions on SCOM -SCVMM Integration. Please help me in answering them. 1) Can multiple SCVMM servers be integrated with the same SCOM Management Server? 2) Does uninstalling an older version of the SCOM Console on the SCVMM serve

  • PR to PO Error

    Hi ALL , I am creating a Sales order for Configurable material with Item Category TAS , it is creating PR but when  trying to create PO , it is giving error as Requisition xxxx ,item 00010 assigned to other order account Not possible to determine any

  • Project going from CSV files to XML files

    What is the best XML parser to use now? I do not want to tie us into something that is stale or not up to date. Dom4J hasn't been updated since May of 2006. Any advice is appreciated.

  • Date Part or Format Date

    Hi, I have a datetime column in the universe. The format of the date is "mm/dd/yyyy hh:mm:ss when users run report they only want to see the format as MON-YYYY. what syntax shall I use can anybody help.