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?

Similar Messages

  • 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

  • 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.

  • 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

  • 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();

  • 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;

  • JComboBox AutoCompleteDecorator & MouseClicked event

    Hi, I have a problem with a JComboBox's MouseClicked.
    I have imported an AutoCompleteDecorator to my combobox but, because of this, whenever I double click on the combo, it doesn't fire an event.
    To get it to fire an event, I have to click exactly on the combobox's border,which is qiute a hastle. Is there a work around for this or another way to implement autocomplete?

    I've also created a different class that does the same thing, AND still gives me the same problem.
    package oma;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.text.*;
    * @author Zweli
    public class AutoComplete extends JComboBox implements JComboBox.KeySelectionManager{
        private String searchFor;
         private long lap;
         public class CBDocument extends PlainDocument {
                public void insertString(int offset, String str, AttributeSet a) throws BadLocationException {
                    if (str==null) return;
              super.insertString(offset, str, a);
                        if(!isPopupVisible() && str.length() != 0) fireActionEvent();
        public AutoComplete(Object[] items) {
            super(items);
         lap = new java.util.Date().getTime();
         setKeySelectionManager(this);
         JTextField tf;
         if(getEditor() != null) {
                tf = (JTextField)getEditor().getEditorComponent();
                if(tf != null) {
                    tf.setDocument(new CBDocument());
                    addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            JTextField tf = (JTextField)getEditor().getEditorComponent();
                            String text = tf.getText();
                            ComboBoxModel aModel = getModel();
                            String current;
                            for (int i = 0; i < aModel.getSize(); i++) {
                                current = aModel.getElementAt(i).toString();
                                if(current.toLowerCase().startsWith(text.toLowerCase())) {
                                    tf.setText(current);
                                    tf.setSelectionStart(text.length());
                        tf.setSelectionEnd(current.length());
                        break;
        public int selectionForKey(char aKey, ComboBoxModel aModel) {
         long now = new java.util.Date().getTime();
            if (searchFor!=null && aKey==KeyEvent.VK_BACK_SPACE &&     searchFor.length()>0) {
                searchFor = searchFor.substring(0, searchFor.length() -1);
            } else {
                //     System.out.println(lap);
                // Kam nie hier vorbei.
                if(lap + 1000 < now)
                    searchFor = "" + aKey;
                else
                    searchFor = searchFor + aKey;
         lap = now;
         String current;
         for(int i = 0; i < aModel.getSize(); i++) {
                current = aModel.getElementAt(i).toString().toLowerCase();
                if (current.toLowerCase().startsWith(searchFor.toLowerCase())) return i;
            return -1;
        public void fireActionEvent() {
            super.fireActionEvent();
    }Thanx, Zweli

  • 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.

  • Another mouseClick event question

    I have a class that extends DefaultTableModel, and implements MouseListener.
    How can I add mouseClicked in it?
    I can add it in class from where I create it, like:
    public void mouseClicked(MouseEvent e) {
      if (e.getClickCount() == 2){
        try{
              System.out.println("Double clicked!");
        } catch (Exception ert) {
              ert.printStackTrace();
    }... but I wolud like to put this action in class that extends DefaultTableModel.
    Thank you in advance!

    You where given the answer in your original posting of this question 4 days ago:
    http://forum.java.sun.com/thread.jspa?threadID=5145277

  • For JTable MouseClick event

    hello, every one, yestoday I make a program with JTable. I know how to do a muti_selection, but I only know use "ctrl + left mouse". I want to use "double click" instead of "ctrl + left mouse".
    So, the problem is I don't know how to write code for it? Who can tell me how to do? Thand you.

    http://java.sun.com/docs/books/tutorial/uiswing/
    Add action listeners to the buttons.

  • Calling mouseClick from another event

    I have some code built in to my mouseClick event that I want to re-use. Is there a way to call the mouseClick code from inside another event. Thanks.....

    Just write a method outside of the event method.
    // INSIDE EVENT HANDLER
    class ActionListener extends blahblahblah {
       public void actionPerformed(ActionEvent e) {
             myReusableMethod(e);
    // outside the event handler, like all the other methods
    public void myReusableMethod(ActionEvent e)
        // do some stuff
    }

  • How to detect control-mo​useclick event

    I'm trying to make the Z-scale max property of an Intensity graph more flexible to modify from the front panel.  In the attached VI, I use an increment/decrement control and just detect a value change event (ignoring the value of the control).  This works fine, although it is a bit of a kludge.
    I'd like to make it more functional though.  My main question is the following:  How can I detect a "control-mouseclick" event?  I plan to use this event to change the Intensity Graph max by a factor rather than by an additive value.
    A second small question:  On the numeric control, is there a way I can get rid of the displayed number whitespace and leave only the increment/decrement buttons?
    Thanks,
    Allan
    Solved!
    Go to Solution.
    Attachments:
    intensity graph scale.vi ‏16 KB
    intensity graph control.jpg ‏21 KB

    tbob,
    Thanks.  Your suggesetion solves my original problem, but it creates another.  With the platmods "ctrl" boolean hooked to a case statement, I can choose between those "ctrl click" and "regular click" cases.  However, with the "mouse down" event, I can't tell if the increment or decrement button was pressed.
    I guess one solution is to replace a single inc/dec control with two booleans controls (increase and decrease) and to have two separate events .  Problem with that is that I'm really piling up event cases, because I'll need several copies of this type of control on my front panel.
    Can you suggest any way to have both inc/dec button and ctrl-mouse functionality?  Maybe there is a way to combine the "value change" and "mouse down" events?
    Allan

  • How to know the row and col numbers of a cell in JTable at mouseclicked

    Hi, I'm coding an app using swing and JTable, in this table I will display the records from a database, now, each time the user has click in any cell I want to display it value, whit this method:
        private void setpuntero(JTable table, int row, int col){
            Object o = table.getValueAt(row, col);
            System.out.println("Valor de la celda: "+o.toString());
    }The mouseclick event was coded like this:
                table.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent e) {
                        setpuntero(table, 1, 3);
                });My question is:
    how in the mouseClicked I can pass to setpuntero() method the dynamic values of the cell that the user clicked?
    In this example, setpuntero(table, 1, 3); I have chosen the cell(1,3) to display the value, but really I don't know how to capture those values dinamically using the mouse click
    Regards
    Herbert

    perhaps:
          public void mouseClicked(MouseEvent e)
            int row = table.getSelectedRow();
            int col = table.getSelectedColumn();
            String selected = table.getValueAt(row, col).toString(); // this will need to be changed if not String data
          }

Maybe you are looking for

  • Need SRM BW Vendor Evaluation Report Names with format

    It would be really appreciable if someone can share the SRM BW Vendor Evaluation Report Names along with the format. Cheers, Sheetika

  • Convert Binary Data into Pdf & send it as attachment in a mail

    Hi Friends, Scenario : The interactive form saved in WebDynpro Application is sent to R/3 in binary format. It has to be converted into pdf and sent it as an attachment in mail to the respective person. Kindly help on these issues : 1. How to receive

  • Using JBoss to distribute Java App

    Hello... How can I distribute my JAVA application which has been developed using EJB in JBoss ? What CLASSES should I attached with the JAVA application ? I believe in Weblogic we should do the same thing, right ? Please Help. Thank you.

  • There is no airport option in network

    I have searched to see if i have the airport card and i do. There is a strange problem though and I dont know how to go about it. When I am in system profiler I click on Network and I see all the active services, Airport, Bluetooth DUN, Bluetooth PAN

  • SKU for a material

    hello gurus what is SKU for a materiial i have given a file with combination of plant material  storage location quantity and unit  i want to print the sku what will be the sku i mean the combination of above which fileds make SKU regards afzal