MouseClick event on a JLabel inside a TableCell

I'm building a table and each row contains 5 cells:
3 uneditable text labels
edit icon
del icon
I want to open a dialog to edit the whole row when I click on the edit icon and delete the row when I click on the del icon.
But the problem is that when I define a listener inside the cell it seems like the event is never raised or blocked by the JTable.
I've also tried setting a custom cell editor, but have some other problems releted to the fact that I don't change the cell contents, but all the row content.
Does anybody have an idea on how to reach this goal?
Thank you
Simone

2 last columns have to be uneditable.
Add MouseListener to JTable only
public void mouseClicked(MousEvent e){
  switch(yourTable.columnAtPoint(e.getPoint())){
    case 3://edit
      // --- do edit ---
      break;
    case 4://delete
      // --- do delete ---
      break;

Similar Messages

  • How do I assign a mouseclick event Listener to a simplebutton already nested in a movie clip when it's dropped on stage?

    I'm trying to assign a mouseclick event listener to a simplebutton nested within a movie clip's later frames, starting at frame 2 and up. This card, however, is not added to my game until later, and when the player clicks on it/turns it over.
    There are four files involved in this program:
    #1 The main actionscript file, which corresponds to
    #2 my dreamQuester .fla file.
    #3 my artifactCard file movieClip's corresponding .as file,
    #4 my combo1.as file corresponding to a an instance of a simpleButton named combo1 that is already
    nested --and this instance is already named-- inside/as a child of said artifactCard movieclip.
    What I've done so far isn't working:
    In my main dreamQuester.as file, when a player clicks on an artifactCard, its MOUSE_DOWN event
    listener takes them to this function (clickArtCard), where the trouble is at:
    // player clicked on the artC card--which is a child of posArt1 on stage--to turn card over:
            function clickArtCard(a_event:MouseEvent) {
                var thisArtCard:artifactCard = (a_event.target as artifactCard);
                thisArtCard.gotoAndStop(unclickedArt1);  // go to frame number of artifact
                                    // card where combo1 button is.
                thisArtCard.removeEventListener(MouseEvent.CLICK,clickArtCard);
                thisArtCard.buttonMode = false;
                trace("combo1.combo is:" + combo1.combo);
                trace("posArt1.artC.combo1 is:" + posArt1.artC.combo1);
                posArt1.artC.combo1.addEventListener(MouseEvent.MOUSE_DOWN, comboClickedWHO);
    when the artC card--the static public instance of artifactCard--is clicked, it only gets to the
    trace("posArt1.artC.combo1 is:" + posArt1.artC.combo1); which returns this error message:  
    TypeError: Error #1010: A term is undefined and has no properties.
        at MethodInfo-61()
    So do how would I declare a static public variable of this simpleButton at the start of my main .as
    file to make it defined to get a mouseDown actionListener into my pre-existing-and-named-instance
    combo1 simpleButton?
    perhaps there is a way, while the debug movie program is running, to click on the simpleButton and see exactly
    what it's parent heirarchy is, to see the name of all parents above the simpleButton incase they are
    different then what I think?
    (just in case, I was hoping to squeeze a zip file containing these files to be less than 9MB incase someone was willing to look at my files to see what I've done so far, but 9 megs is just too big! even though all graphics I've imported where turned into vector graphics with trace bitmap. I wish there was a way to check the file size of each symbol in Flash CS4, here...)
    Thank you so much for any help!
    ~Ethan

    Just use a
    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
    function keyPressed(event:KeyboardEvent):void {
         //trace(event.keyCode);
         if(event.keyCode == ???){
              // play the sound
    Where I show the "???" you would replace with the keyCode for the key you want pressed for that sound.  To determine the keyCode you can use the trace line that I have commented out.
    Note that when testing in Flash you often need to disable the keyboard shortcuts in the Flash Player in order to be able to use alot of the keys.  You will find this option in the Control menu options in the player.

  • How to handle mouseclicked events in a ListView node correctly?

    Hi
    We want to simulate table rows and headers with a ListView. We have an additional requirement that when a particular row is selected, a X icon will appear at the last column. Clicking which will remove the row from the table.
    A snippet from the implementation is given below
    public class SampleList extends ListView{
        function getRow(row :Row, index:Integer, cell:ListCell):Node {         
             HBox {
                    var closeView : Image
                    content : [
                    Label {textWrap:true, text: bind row.id, layoutInfo: bind LayoutInfo {width:width * .2, height:height * .02 }}, //some column 1
                    Label {textWrap:true, text: bind row.name, layoutInfo: bind LayoutInfo {width:width * .12, height:height * .02 }}, //some column 2                                               
                    close = ImageView {
                                            image : Image{url:"close.png"}
                                            disable: bind cell.selected and not cell.empty
                                            pickOnBounds : true                                   
                                            onMouseClicked : function (event):Void{
                                              if (not close.disable)
                                            //delete from row from model (Row)
                                            } //close column
         override var cellFactory =  function () {     
                def cell : ListCell = ListCell {       
                onUpdate:  function() {                    
                        def item = cell.item;              
                        cell.node = if (item == null) null; else getRow(cell.item as Row, cell.index,cell);                                          
    }      The problem with the code is that the mouse clicked event used by the close button is multiplexed - Firstly - the application logic - it is used to delete the row from the model and secondly - the ListView control - uses it to trigger a item selection internally. As a result, if you click on a row which is not yet selected (in the sense that it is highlighted) at the exact location of the X icon, the row is deleted without it having been ever highlighted
    If you note the code above, you will notice that the close image's mouseclicked event checks cell.selected before deleting it. And cell.selected is true even though the list has not been highlighted
    Any workarounds for this problem would be appreciated
    Thanks
    Dhruva

    User, please always tell us your jdev version.
    In general you use a valueChangeListener which is fired when the user tabs out of the field...
    Timo

  • MouseClicked event = enter key doesnt work

    Hello,
    when I make some JButoon and add to it MouseClicked event (witch handles some code) everything works fine. But when I mark it with TAB then press ENTER button wont "doClick".
    So I found out that actionPerformed might be the right handler, but I dont understand why there is also mouseClicked event?
    Is actionPerformed event what I need (to work either with LMB or ENTER key) ?
    Are there any disatvantages of actionPerformed event comparing to mouseClicked event?

    The spacebar, not the Enter key, is the default keyboard trigger for a button that has the focus (and not just in Java).
    If you really want the focused button to respond to the Enter key, search this forum for"DefaultButtonFollowsFocus".
    db

  • Mouse over event for every word inside a text?

    I want to do a separate mouse over event for every word inside a text.
    or at least get the string below the mouse cursor.
    any hint?
    henry

    There are no events for it but you can use TextField.getCharIndexAtPoint() to determine the character where the mouse is over, and from there you can work out the word where the mouse is over.

  • MouseClicked event

    I have been having some inconsistencies with mouseEvents not firing. I have a mouseClicked event handler assigned to a radio button within a JTable. Occasionally it does not register clicks of the mouse - which obviously causes all manner of problems. I have traced the problem down and it appears to be that the mouseClicked is affected by moving the mouse between pressing and releasing - even if the mouse doesnt exit the radio button (mouseExited). I have got around this by changing to a mouseReleased but my question is:
    Is this the normal behaviour or is there some sort of bug or perhaps some problem with the way they are being used.
    I have researched further and this seems to happen to not just be tied to my circumstances - if you go to this address and run the MouseEventDemo you will see that if you move the mouse between clicking and releasing no mouseClicked event fires: http://java.sun.com/docs/books/tutorial/uiswing/events/mouselistener.html
    Or am i being stupid?

    Hi georgemc,
    With regards to whether its best to use with a radio button - probably not but that was just one example of where it is being used. The reason in that case i have needed to use a mouse event on the radio button is to be honest because i cant get a radio button correctly set up within my JTable and so i have had to create an extra column with another radio button and then emulate a radio buttongroup by having the negation of the boolean of the selected radio button set as the value of the other by my mouse listener! This mouse listener also caches changes for later saving back to db
    In an ideal world i would have these two columns in a button group or possibly even better have on bit of data being represented as a pair of radio buttons
    What type of listener would you suggest in the hypothetical situation that i had a working set of radio buttons within a JTable?

  • Intercept a mouseclick event with a background running application

    Ciao to everyone.
    My name is Alessandro and "i have a problem"...
    I want to count every click of my mouse with an application running in background.
    How can i intercept any mouseclick event, also those occurring out of the application?
    I work with Windows XP.
    Thanks and excuse me for my bad english.

    As far as we know when a Java swing application loses focus you can not handle the click being generated by the user.
    Have a look at the following source:
    http://java.sun.com/docs/books/tutorial/uiswing/events/mouselistener.html
    We have developed routines for that kind of handling in C+ and set up java JNI in order to retrieve them, but they are low level routines that need to handle interruptions from the main board (not recomended for average users).
    Answer provided by http://www.consultoriajava.com

  • What is wrong with the mouseClicked event?

    there is a weird problem with my program: I constructed a panel with two componets(I constructed a new class for the component that extends TextArea);Both components are registered in a mouseClicked event(when I click the component, the text in the component will display).Eveything seems OK when I click one component first.But when I click other one, the text in the component will display twice,like I click twice. if I go back to first component,the text in the first one will display three times, like I clicked three times and so on.
    Does anybody can give me some hints?
    thanks in advance

    please check the codes related to event:
    public class VectorCellEditor extends MultilineCellEditor implements MouseListener
              public VectorCellEditor()
                   super();
              public void initialize( InitialEvent ev,CellInfo info,Object o)
                   String str="";
                   if(o==null)
                        str ="";
                   else if(o instanceof String)
                        str =(String)o;
                   else if(o instanceof Vector)
                        String dateString =((Data)(((Vector)o).firstElement())).getDateString();
                        String dataString="";
                        for( int i = 0;i<((Vector)o).size();i++)
                             dataString = dataString+((Data)((Vector)o).elementAt(i)).toString()+"\n";
                        str = dateString+"\n"+dataString;
                   super.initialize(ev,info,str);
                   super.setEditable(false);
                   addMouseListener(this);
              public void mousePressed(MouseEvent e){}
              public void mouseReleased(MouseEvent e){}
              public void mouseEntered(MouseEvent e){}
              public void mouseExited(MouseEvent e)
              public void mouseMoved(MouseEvent e){}
              public void mouseClicked(MouseEvent e)
                   String s = this.getText();
                   calendar.area.append(s);
         }

  • JTextArea problem: mouseClicked event irregular

    My application allows user to add several CalcArea objects (a subclass of JPanel) in a big JPanel. Highlight of ClassArea class is given below.
    Strangely, I find that once in a while, mouseClicked event is not fired. It is very critical for my user to select a particular CalcArea and modify/update the currently selected CalcArea. It is very much annoying to find that the mouseClicked event occurs irregularly. Please advise me how I can make sure mouseClicked event occurs when user clicks on the desired CalcArea. Thanks.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.math.*;
    import javax.swing.border.*;
    import java.awt.print.*;
    public class CalcArea extends JPanel implements MouseListener, FocusListener
       JTextArea ta;
       DrawPanel dp; //subclass of JPanel
       static int iCount=0;
       static int selectedMemberID=-1;
       int memberID;     //unique ID (0-based)
       //constructor
       public CalcArea(String strID....)
       }  //constructor ends
       public void mousePressed(MouseEvent e)
       } //method mousePressed ends
       public void mouseClicked(MouseEvent e)  //***Problem here
         selectedMemberID= memberID;
         System.out.print("mseClicked***");
       public void mouseReleased(MouseEvent e) {}
       public void mouseEntered(MouseEvent e) {}
       public void mouseExited(MouseEvent e) {}

    Is there any way to solve it? I don't really understand what you are trying to accomplish, but maybe somthing like the following will help:
    e.getComponent().getGraphics();
    e.getComponent().getParent().getGraphics();

  • Implementing JLabel MouseClick Event handler

    Hey Everyone!
    I am currently in the process of implementing a small GUI application for myself. Instead of using JButton, I used a JLabel as it allows me to show an image to be used as a button. I know how to use JButton's events but I have no clue how to implement a Mouse Click event for JLabel. Any ideas/code/help appreciated!!! Also if you provide code, it would be a bonus for me if you could explain it as well and how it works. You can assume I know basic Object Orientated experience. :) Thanks a bunch.

    Sorry for double posting. please donot reply to this thread.

  • How to select JLabel inside a JTable

    hi all,
    I have a Jtable which has own renderer so it can store components in it. I have added a Jlabel one of its cells but when I select that row the label stays upon the selected background color. here is a sample screenshot to decribe my problem clearly [http://www.imagecross.com/06/image-hosting-view-01.php?id=6570label.jpg]
    is there any way to select the label inside selected background color.
    - I have already tried to make the label not opaque but it didnt work -
    thanks...

    I have added bold parts of the code below. if you use other components you can make a type casting and do what you want.
    thanks again..
    class ComponentRenderer *extends JComponent*  implements TableCellRenderer
        public Component getTableCellRendererComponent(JTable table, Object value,
              boolean isSelected, boolean hasFocus, int row, int column) {
        *     JLabel l = (JLabel)value;*
        *     if(isSelected) {*
        *          l.setForeground(Color.BLUE);*
        *          l.setOpaque(true);*
        *          l.setBackground(new Color(184, 207, 229));*
        *     else {*
        *          l.setForeground(Color.BLACK);*
        *          l.setOpaque(true);*
        *          l.setBackground(Color.WHITE);*
            return l;
        /*public ComponentRenderer() {
    }

  • Remove Child and Event.SOUND_COMPLETE not working inside movie clip. What's the problem?

    I have a movie clip that is called to the stage. The user then clicks a button and music plays. As the music starts, another movie clip is called, a simulation of  an equilizer. There are several things that should happen:
    1) When the user closes the movie clip the music is supposed to stop playing and the equilizer movie clip is removed. What actually happens is the music stops playing but  the equilzer movie clip is not removed.
    2) When the music is finished playing the equilzer is supposed to be removed from the stage and the play button is reactivated. But none of that happens. When I click on the movie clip a second time equilizer is still there and the play button is not reactivated.
    Here's the code that calls the movie clip to the stage.
    stage.addEventListener(MouseEvent.MOUSE_DOWN, goButtons);
    function goButtons(event:MouseEvent):void
        if (event.target == Song_bnt)
            SoundMixer.stopAll();
            addChild(myPlaySong);
            myPlaySong.x = 304;
            myPlaySong.y = 105;
            //event.stopImmediatePropagation();
    Here's the code in the movie clip:
    import flash.media.Sound;
    import flash.events.Event;
    stop();
    var playRayJaySong:RJSong;
    var playRayJaySongChannel:SoundChannel;
    var equilizer:Equilizer;
    equilizer = new Equilizer();
    playRayJaySong = new RJSong();
    //Plays music, inactivates buttons, and adds the equilizer to the stage.
    PlaySongRJClip.addEventListener(MouseEvent.MOUSE_DOWN, songPageButton);
    function songPageButton(event:Event):void
        playRayJaySongChannel = playRayJaySong.play();
        PlaySongRJClip.visible = false;
        ClicktoPlaySong.visible = false;
        addChild(equilizer);
        equilizer.x = 269;
        equilizer.y = 246;
    //Removes the equilizer from the stage when the music is complete.
    PlaySongRJClip.addEventListener(Event.SOUND_COMPLETE, rjSoundComplete);
        function rjSoundComplete(e:Event):void
        PlaySongRJClip.visible = true;
        ClicktoPlaySong.visible = true;
        removeChild(equilizer);
    //Removes the equilizer and event listeners from stage and calls dispatch event to close the movie clip.
    closeSong_bnt.addEventListener(MouseEvent.MOUSE_DOWN, CloseSong);
    function CloseSong(event:MouseEvent):void
        removeChild(equilizer);
        dispatchEvent(new Event("RemoveMSong"));
        PlaySongRJClip.removeEventListener(MouseEvent.MOUSE_DOWN, songPageButton);
        PlaySongRJClip.removeEventListener(Event.SOUND_COMPLETE, rjSoundComplete);
    //Removes the MovieClip from the stage when the user clicks on the close button inside the MovieClip.
    myPlaySong.addEventListener("RemoveMSong", RemoveSongClip);
    function RemoveSongClip(e:Event):void
        SoundMixer.stopAll();
        removeChild(myPlaySong);
    Any thoughts?

    I figured out the problem. Here's how I reorganized the code (all in one frame).
    //Code for Ray Jay song.
    var playRayJaySong:RJSong;
    var playRayJaySongChannel:SoundChannel;
    playRayJaySong = new RJSong();
    myPlaySong.equilizer_inst.visible = false;
    //Plays the song.
    myPlaySong.PlaySongRJClip.addEventListener(MouseEvent.MOUSE_DOWN, songPageButton);
    function songPageButton(event:Event):void
        playRayJaySongChannel = playRayJaySong.play();
        playRayJaySongChannel.addEventListener(Event.SOUND_COMPLETE, rjSoundComplete);
        myPlaySong.equilizer_inst.visible = true;
        myPlaySong.PlaySongRJClip.visible = false;
        myPlaySong.ClicktoPlaySong.visible = false;
    //Removes the MovieClip from the stage when the user clicks on the close button inside the MovieClip.
    myPlaySong.closeSong_bnt.addEventListener(MouseEvent.CLICK,RemoveSongClip);
    function RemoveSongClip(e:Event):void
        SoundMixer.stopAll();
        removeChild(myPlaySong);
        myPlaySong.equilizer_inst.visible = false;
        myPlaySong.PlaySongRJClip.visible = true;
        myPlaySong.ClicktoPlaySong.visible = true;
        playRayJaySongChannel.removeEventListener(Event.SOUND_COMPLETE, rjSoundComplete);
    //Resets all of the movieclips to their orginal state.
    function rjSoundComplete(e:Event):void
        myPlaySong.equilizer_inst.visible = false;
        myPlaySong.PlaySongRJClip.visible = true;
        myPlaySong.ClicktoPlaySong.visible = true;
    Thanks all for your suggests and input.

  • Generating events from a control inside an array of clusters

    Hi, I have a question regarding UI events. I would like to capture a mouse down event generated in a string control inside of an array. Each element of the array is a cluster that has a Boolean control, a numeric control and a string control. When I try to add an event to handle the mouse down the only option available in the event structure is the one available for the entire array. If this is not possible to map event from the individual controls inside of the each cluster that are part of the array, could you provide with an alternate way of "knowing" when the string control is selected. The application has a touch screen without a keyboard and mouse. I need to display the touch screen graphic keyboard when the textbox is selected.
    Thanks,
    Diego F.

    I'm not sure, but I think your only option may be to do some calculations. The mouse down on the array will give the coordinates of the click in VI coords. You can get the coords and size of the cluster and the coords and size of the string using their property nodes. Then, you have to calculate whether the click was on one of the visible strings using addition, subtraction and quotients. Once you make a subVI out of this, it should be easy to use.
    You should watch out for the index display and the label, as they change the values of the coords. I'm sorry, I can't think of any easier way to do this.
    Correction - I just thought of one. If you use the KeyFocus property on the string inside the mouse down event, it seems to work. I'm not sure whether this will work when bringing the keyboard to the front, which is why I left the other suggestion in place. Here's my test (7.0)
    Try to take over the world!
    Attachments:
    key1.vi ‏29 KB

  • Event handling for UIImageView inside UIScrollView

    Hi, I have a UIScrollVIew. I added a UIImageView inside it. I found that UIImageView did not reveive any events. No matter what I do, there is only image zoom in out and flip. How can I enable UIImageVew to receive some events?
    Thanks,
    fm

    Did you set userInteractionEnabled per my reply to the question you posted earlier today? [http://discussions.apple.com/thread.jspa?messageID=9043590#9043590]

  • Trying to Update JLabel inside a ActionEvent

    I read that you can't update the UI while inside an ActionEvent ... I have a very small program and think that creating a new thread would be over the top for this. Can anyone offer any other ideas ? Here is the action event listener.
    public void actionPerformed(ActionEvent ae)
         String command = ae.getActionCommand();
         if(command.equals("createFile"))
              completedL.setText("Generating spread sheet, please wait..... ");
              completedL.repaint();
              System.out.println(ae.getActionCommand());
              storeNumber=storeNumberF.getText();
              cardNumber= cardQtyF.getText();
              found = info.find(storeNumber);
              if(found != null)
                   System.out.println("Found " + found.getStoreNumber());
                   storeNumber =found.getStoreNumber();
                   System.out.println("Last card # is " + found.getCardNumber());
                   cardValue =found.getCardNumber();
              else
                   System.out.println("can't find " + storeNumber);//put system dialog box here !!
              h = Integer.parseInt(storeNumber);
              x = Integer.parseInt(cardNumber);
              System.out.println("Store # : " + h +" Card Qty " + x);
              try
                   makeSheet(h,x,cardValue);
              catch(IOException ioe)
                   System.out.println(ioe);
    }Been looking at this for a few days and have tried various things. I'd be willing to give threads a shot, but to me it seems like there should be another way.
    -Ben

    makesheet() is the one that takes a while. I made the following adjustments and it didn't update the label until the end just like before :
    public void actionPerformed(ActionEvent ae)
         String command = ae.getActionCommand();
         if(command.equals("createFile"))
              completedL.setText("Generating spread sheet, please wait..... ");
              completedL.repaint();
              System.out.println(ae.getActionCommand());
              storeNumber=storeNumberF.getText();
              cardNumber= cardQtyF.getText();
              found = info.find(storeNumber);
              if(found != null)
                   System.out.println("Found " + found.getStoreNumber());
                   storeNumber =found.getStoreNumber();
                   System.out.println("Last card # is " + found.getCardNumber());
                   cardValue =found.getCardNumber();
              else
                   System.out.println("can't find " + storeNumber);//put system dialog box here !!
              h = Integer.parseInt(storeNumber);
              x = Integer.parseInt(cardNumber);
              System.out.println("Store # : " + h +" Card Qty " + x);
         //     try
                   Runnable makeSheetRun = new Runnable()
                        public void run()
                             try
                                  makeSheet(h,x,cardValue);
                             catch(IOException ioe)
                                  System.out.println(ioe);
                   SwingUtilities.invokeLater(makeSheetRun);
         //     catch(IOException ioe)
         //          System.out.println(ioe);
    }

Maybe you are looking for