Disabled button fires events to event structure

Hi all,
I was trying to disable a Button on the frontpanel by using its enabled property while the event was executed. The ide wa not to create more events of this buttopn while its fucntion was executed. However thsi did not work.It was creating events even though it was greyed out.
I troied two different versions:
1) in the event case of the button (value changed) in a sequence I first dispalbned the button, execuded the code and then enabled it again
    Result: All events were generated even though the button was greyed out
2)  in the event case of the button (value changed) in a sequence I disbaled the Button and then started a second event. The Second event executed the code and then enabled the Button egain
   Result: Even though the Button was greyed out events were generated
3) in the event case of the button (value changed) in a sequence I first dispalbned the button, execuded the code and in the timeout event I thenenabled it again
   Result: No additional events were generated
it seems that the enable state of the button is analysed at teh time when the event is execute din teh event case but not at the time when it was created?
So I Tried the Time Input of the case expecting that it woudl give me a time stamp of the time when the key was pressed - but instead it gave me the time point when teh event was executed...
Teh only othe rsolution was to set teh cursor to busy (however I dont want to see the changed cursor during the busy cycle)
So how can I make shure that no additional events are fired during the time teh code of the Button s executed?
Thanks for any help,
Rainer

to altenbach:
The evet takes about one or two seconds - I checked the behaviour as shown in the attached examples with LV 8.5, LV 2010, TV2011, LV2012 - allways exactly the same behaviour.
It does not make any difference weather you use switch when pressed or latched when pressed.
It does not make any difference weathe ror not you tag "Lock front panel" for that event
to sth:
> If you disable a front panel control (ie the button) you cannot click on it and a value changed event will not be
generated.
This is my experience so far as well, but if you disable and enable the control within the same event it does not work (see attaced example 1) and 2). It only works if you do the enable in the timeout event.
> The time stamp from the event case left hand property is the time of the event not the time of execution.
> If you ask for the timer value inside the event case it will be the time of event case executing.
In the attached exampel this is not the case. The time differecne between the Time input on the left and the Tick count
placed in the event is 0 for all events generated whil the button is supposed to be disabled.
As I wrote before, the explanation I have for this behaviour is that the events are generated by windows weather or not
the button is disabled and they are queued to the event cue. Only when the event is handeled LabVIEW tests weather
or not the button is disabled and ignores the event in case it is disabled. If the Disabling and enabling is done
withim the same event the button pressed events are added to thw event queue and the button is set to enabled before the  next event (button pressed while it shoul be disabled) is handeled. When that event is handeled the button is enabled again (by the original event) and therefore the evenet is not ignored (because by the time of execution of the event the button is enabled again).
If the button is enabled in the timeout event instead of the button change value event all event in teh queue are executed before teh timeout event. At their time of execution therefore the button is steill disabled. Only then the timeout event enables the button again.
If the vi is set to busy (sand clock) this is activating actually a windows function/property and no events are queued to teh event queue by windwos. Therefore no button change event is added to teh queue.
Funtciomn of the 3 attached Vis (LV 2010):
Run the Vi, then press the Test button once - when it is greyed out click it a few more times. The test button value
changed event has a 2 second delay. You will see the event counter increase, and you will see the time difference
between the time property on the left of the event and the tick count vi whci is displayed in the waveform chart.  
DisableButton 1: Disable and enable are ste in teh same event  
DisableButton 2: The button is disabled then a second event is called to do the work and then enable teh button again
DisableButton 3: The Button is disabled in button change value event and it is enabled again in teh timeout event.
Attachments:
DisableButton1-3.zip ‏29 KB

Similar Messages

  • Disabled button fires an event ?!   :-O

    Hi, friends!
    I've never thought about the next issue: why desabled button can fire an et_Click event?
    I havn't no idea to check that!
    I thought before that enabled=false is the method to prevent et_Click event for that item, but...
    <b>Is it a bug or feature?</b>
    I'm talking now about v6.5, what can you say about that situation on v6.7?

    It is not a bug, the SDK is simply informing you that the user clicked on something.  You can click on other disabled items such as edittexts and they will also generate the click events for you. 
    The important difference with a disabled button is that the et_ITEM_PRESSED event won't be triggered.  The et_ITEM_PRESSED event is the correct one to use to detect the user pressing a button.
    John.

  • Button Fire Event Multiple Times

    Hey everyone.  I've somewhat inherited a LabVIEW program for a project I'm working on.  I need to fire an event in an event structure 20 times in a row to fully collect my data.  Right now i just have the event structure connected to a slider so i just slide it enough and it completes the 20 events needed.  Is there a way I can make one button fire an event 20 times?  I need the while loop for the entire program to run during these 20 times so a simple loop around the event code won't work.  Any ideas?  Thanks guys.

    I'd use another solution.
    When the button is pressed, start a dynamic VI that does the aqcuisition.
    When the VI is done, it sends a user event (or a value (signalling) event to
    some control), so the main VI knows it's done. By doing this, you seperate
    the DAQ and the MMI, which is good. Both VI's are kept simple. Put the data
    in a buffer, or pass it in the user event data.
    Timing and event structures are difficult. It's very inconvenient to exectue
    an event case every X sec. without using a dynamic VI (or parrallel loop).
    Using the time out event has it's own problems. The TO event is called when
    no other event occured for the given period. So if you'd add a mouse over
    event (as an example) the TO case isn't called at all when the mouse
    moves...
    You could also start a dynamic VI that creates a user event (or value
    (signalling) 20 times at some interval, and then quits. But it's just as
    complex as a dynamic DAQ vi, and less elegant.
    Regards,
    Wiebe.

  • Useful Code of the Day:  Button fires events while held

    Have you ever been making a GUI application with Swing and used some JButtons? Fun, right? Have you ever wanted to have the button fire action events while the button was being held down? Well, if you just stick a plain JButton in your application and press and hold the mouse button on it, you'll see it doesn't do anything except sit there looking pressed in. Insolent button!
    RepeatButton (code below, couldn't think of a better name) is a JButton subclass which contains a timer that is set when the mouse button presses the button, and after a slight initial delay (configurable), fires action events to all registered action listeners repeatedly (with another configurable delay between events) until either the mouse is released or the mouse moves out of the button (it starts up again if the mouse moves back over without releasing the mouse button) or the button is disabled. The event modifiers are passed on as well, so you know if the shift or control buttons (or whatever) are being pressed at the same time.
    There is also a method to disable the repeated action firing while holding. This, in effect, turns the button into a normal JButton, if needed.
    There is a main method for testing which will show a button in a frame and print out the action command for each action event fired.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import javax.swing.*;
    import javax.swing.event.*;
    * <code>RepeatButton</code> is a <code>JButton</code> which contains a timer
    * for firing events while the button is held down.  There is a default
    * initial delay of 300ms before the first event is fired and a 60ms delay
    * between subsequent events.  When the user holds the button down and moves
    * the mouse out from over the button, the timer stops, but if the user moves
    * the mouse back over the button without having released the mouse button,
    * the timer starts up again at the same delay rate.  If the enabled state is
    * changed while the timer is active, it will be stopped.
    * NOTE:  The normal button behavior is that the action event is fired after
    * the button is released.  It may be important to konw then that this is
    * still the case.  So in effect, listeners will get 1 more event then what
    * the internal timer fires.  It's not a "bug", per se, just something to be
    * aware of.  There seems to be no way to suppress the final event from
    * firing anyway, except to process all ActionListeners internally.  But
    * realistically, it probably doesn't matter. 
    public class RepeatButton extends JButton
              implements ActionListener, MouseListener {
          * The pressed state for this button.
         private boolean pressed = false;
          * Flag to indicate that the button should fire events when held. 
          * If false, the button is effectively a plain old JButton, but
          * there may be times when this feature might wish to be disabled. 
         private boolean repeatEnabled = true;
          * The hold-down timer for this button.
         private Timer timer = null;
          * The pressed state for this button.
         private int delay = 60;
          * The pressed state for this button.
         private int initialDelay = 300;
          * Holder of the modifiers used when the mouse pressed the button. 
          * This is used for subsequently fired action events.  This may change
          * after mouse pressed if the user moves the mouse out, releases a key
          * and then moves the mouse back in. 
         private int modifiers = 0;
          * Creates a button with no set text or icon.
         public RepeatButton() {
              super();
              init();
          * Creates a button where properties are taken from the Action supplied.
          * @param  a  the button action
         public RepeatButton(Action a) {
              super(a);
              init();
          * Creates a button with an icon.
          * @param  icon  the button icon
         public RepeatButton(Icon icon) {
              super(icon);
              init();
          * Creates a button with text.
          * @param  text  the button text
         public RepeatButton(String text) {
              super(text);
              init();
          * Creates a button with initial text and an icon.
          * @param  text  the button text
          * @param  icon  the button icon
         public RepeatButton(String text, Icon icon) {
              super(text, icon);
              init();
          * Initializes the button.
         private void init() {
              this.addMouseListener(this);
              // initialize timers for button holding...
              this.timer = new Timer(this.delay, this);
              this.timer.setRepeats(true);
          * Gets the delay for the timer of this button. 
          * @return  the delay
         public int getDelay() {
              return this.delay;
          * Set the delay for the timer of this button. 
          * @param  d  the delay
         public void setDelay(int d) {
              this.delay = d;
          * Gets the initial delay for the timer of this button. 
          * @return  the initial delay
         public int getInitialDelay() {
              return this.initialDelay;
          * Sets the initial delay for the timer of this button. 
          * @param  d  the initial delay
         public void setInitialDelay(int d) {
              this.initialDelay = d;
          * Checks if the button should fire events when held.  If false, the
          * button is effectively a plain old JButton, but there may be times
          * when this feature might wish to be disabled. 
          * @return  if true, the button should fire events when held
         public boolean isRepeatEnabled() {
              return this.repeatEnabled;
          * Sets if the button should fire events when held.  If false, the
          * button is effectively a plain old JButton, but there may be times
          * when this feature might wish to be disabled.  If false, it will
          * also stop the timer if it's running.
          * @param  en  if true, the button should fire events when held
         public void setRepeatEnabled(boolean en) {
              if(!en) {
                   this.pressed = false;
                   if(timer.isRunning()) {
                        timer.stop();
              this.repeatEnabled = en;
          * Sets the enabled state of this button.  Overridden to stop the timer
          * if it's running.
          * @param  en  if true, enables the button
         public void setEnabled(boolean en) {
              if(en != super.isEnabled()) {
                   this.pressed = false;
                   if(timer.isRunning()) {
                        timer.stop();
              super.setEnabled(en);
          * Handle action events.
          * @param  ae  the action event
         public void actionPerformed(ActionEvent ae) {
              // process events only from this components
              if(ae.getSource() == this.timer) {
                   ActionEvent event = new ActionEvent(
                        this, ActionEvent.ACTION_PERFORMED,
                        super.getActionCommand(), this.modifiers);
                   super.fireActionPerformed(event);
              // testing code...
              else if(testing && ae.getSource() == this) {
                   System.out.println(ae.getActionCommand());
          * Handle mouse clicked events.
          * @param  me  the mouse event
         public void mouseClicked(MouseEvent me) {
              // process events only from this components
              if(me.getSource() == this) {
                   this.pressed = false;
                   if(this.timer.isRunning()) {
                        this.timer.stop();
          * Handle mouse pressed events.
          * @param  me  the mouse event
         public void mousePressed(MouseEvent me) {
              // process events only from this components
              if(me.getSource() == this && this.isEnabled() && this.isRepeatEnabled()) {
                   this.pressed = true;
                   if(!this.timer.isRunning()) {
                        this.modifiers = me.getModifiers();
                        this.timer.setInitialDelay(this.initialDelay);
                        this.timer.start();
          * Handle mouse released events.
          * @param  me  the mouse event
         public void mouseReleased(MouseEvent me) {
              // process events only from this components
              if(me.getSource() == this) {
                   this.pressed = false;
                   if(this.timer.isRunning()) {
                        this.timer.stop();
          * Handle mouse entered events.
          * @param  me  the mouse event
         public void mouseEntered(MouseEvent me) {
              // process events only from this components
              if(me.getSource() == this && this.isEnabled() && this.isRepeatEnabled()) {
                   if(this.pressed && !this.timer.isRunning()) {
                        this.modifiers = me.getModifiers();
                        this.timer.setInitialDelay(this.delay);
                        this.timer.start();
          * Handle mouse exited events.
          * @param  me  the mouse event
         public void mouseExited(MouseEvent me) {
              // process events only from this components
              if(me.getSource() == this) {
                   if(this.timer.isRunning()) {
                        this.timer.stop();
          * Testing flag.  Set in main method.
         private static boolean testing = false;
          * Main method, for testing.  Creates a frame with both styles of menu.
          * @param  args  the command-line arguments
         public static void main(String[] args) {
              testing = true;
              JFrame f = new JFrame("RepeatButton Test");
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JPanel p = new JPanel();
              RepeatButton b = new RepeatButton("hold me");
              b.setActionCommand("test");
              b.addActionListener(b);
              p.add(b);
              f.getContentPane().add(p);
              f.pack();
              f.show();
    "Useful Code of the Day" is supplied by the person who posted this message. This code is not guaranteed by any warranty whatsoever. The code is free to use and modify as you see fit. The code was tested and worked for the author. If anyone else has some useful code, feel free to post it under this heading.

    This makes word completion possible for JTextArea:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    import java.util.*;
    * This class provides word completion for JTextArea.
    public class WordCompleteArea extends JTextArea {
        private boolean isTextComplete = true;
        public WordCompleteArea (Document doc, String text,
                                      int rows, int columns, KeyStroke expandKey) {
            super (doc, text, rows, columns);
            String s = "word-complete";
            Action wordComplete = new AbstractAction () {
                public void actionPerformed (ActionEvent e) {
                    wordComplete ();
            getInputMap ().put (expandKey, s);
            getActionMap ().put (s, wordComplete);
        public WordCompleteArea (Document doc, String text, int rows, int columns) {
            this (doc, text, rows, columns,
                            KeyStroke.getKeyStroke ("ctrl pressed SPACE"));
        public WordCompleteArea (Document doc) {
            this (doc, null, 0, 0);
        public WordCompleteArea (String text, int rows, int columns) {
            this (new PlainDocument (), text, rows, columns);
        public WordCompleteArea (int rows, int columns) {
            this (null, rows, columns);
        public WordCompleteArea (String text) {
            this (text, 0, 0);
        public WordCompleteArea () {
            this (0, 0);
         * Define if text already written in the JTextArea will be used
         * for expansion.
        public void setTextComplete (boolean b) {
            isTextComplete = b;
         * Find out if text already written in the JTextArea will be used
         * for expansion.
        public boolean isTextComplete () {
            return isTextComplete;
        private String tokenDelimiters = "\t\r\n ,;()[]{}%+/-*<>=&|!\"\'.@#";
         * Get delimiters that form a word.
        public String getTokenDelimiters () {
            return tokenDelimiters;
         * Set delimiters that form a word.
        public void setTokenDelimiters (String s) {
            tokenDelimiters = s;
        // Additional words used for expansion.
        private LinkedList wordCompleteList = new LinkedList ();
         * Add words that will be used as expansion.
        public void addCompleteWords (java.util.List words) {
            wordCompleteList.add (words);
         * Add a word that will be used as expansion.
        public void addCompleteWord (String word) {
            wordCompleteList.add (word);
        private String lastExpanded = null;
        private String lastExpansion = null;
        private Set dontAccept = new HashSet ();
        protected void wordComplete () {
            int caret = getCaretPosition ();
            if (caret == 0)
                return;
            String text = getText ();
            if (caret != text.length () && isCompletionLetter (text.charAt (caret)))
                return;
            StringBuffer sb = new StringBuffer ();
            int index = caret - 1;
            char ch;
            while (index >= 0 && isCompletionLetter ((ch = text.charAt (index)))) {
                sb.append (ch);
                index--;
            if (sb.length () == 0)
                return;
            sb.reverse ();
            String word = sb.toString ();
            String toExpand = word;
            if (toExpand.equals (lastExpansion)) {
                dontAccept.add (lastExpansion);
                toExpand = lastExpanded;
            } else {
                dontAccept.clear ();
            String s = findExpansion (toExpand, caret);
            if (s != null) {
                lastExpanded = toExpand;
                lastExpansion = s;
                replaceRange (s, caret - word.length (), caret);
            } else {
                dontAccept.clear ();
                lastExpanded = null;
                lastExpansion = null;
                int diff = word.length () - toExpand.length ();
                replaceRange ("", caret - diff, caret);
        private boolean isCompletionLetter (char ch) {
            return tokenDelimiters.indexOf (ch) < 0;
        protected String findExpansion (String word, int caret) {
            StringTokenizer st;
            if (isTextComplete) {
                st = new StringTokenizer (getText (), getTokenDelimiters ());
                while (st.hasMoreTokens ()) {
                    String s = st.nextToken ();
                    if (    s.startsWith (word)
                            && s.length () != word.length ()
                            && !dontAccept.contains (s)      ) {
                        return s;
            for (Iterator it = wordCompleteList.iterator (); it.hasNext (); ) {
                st = new StringTokenizer
                                ((String) it.next (), getTokenDelimiters ());
                while (st.hasMoreTokens ()) {
                    String s = st.nextToken ();
                    if (    s.startsWith (word)
                            && s.length () != word.length ()
                            && !dontAccept.contains (s)      ) {
                        return s;
            return null;
        // TEST
        public static void main (String[] args) {
            WordCompleteArea a = new WordCompleteArea ();
            JFrame window = new JFrame ();
            window.getContentPane ().add (a, BorderLayout.CENTER);
            window.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
            window.setSize (300, 300);
            window.setVisible (true);
    }

  • Disabled button generates events

    Hello,
    I have a radio button that I want to disable while a background process is running.
    After the process finishes, I enable the button again.
    However, if the user clicks on the disabled button during the background process, an ActionEvent still gets generated.
    Then when the button is re-enabled, it responds to the event that was generated while it was disabled. I want to prevent my button from responding to events generated while it was disabled.
    I do not want to use the getGlassPane.setVisible(true) technique because I still want my cancel button to be able to generate events during the background process.
    I am using JDK 1.3.1 and my button is in a panel contained in a JFrame application.
    Suggestions?
    Thank you,
    Ted Hill

    Hello,
    I have a radio button that I want to disable while a background process is running.
    After the process finishes, I enable the button again.
    However, if the user clicks on the disabled button during the background process, an ActionEvent still gets generated.
    Then when the button is re-enabled, it responds to the event that was generated while it was disabled. I want to prevent my button from responding to events generated while it was disabled.
    I do not want to use the getGlassPane.setVisible(true) technique because I still want my cancel button to be able to generate events during the background process.
    I am using JDK 1.3.1 and my button is in a panel contained in a JFrame application.
    Suggestions?
    Thank you,
    Ted Hill

  • Mouse Events on Disabled Buttons

    Hi,
    In my application I should make a disabled button to show a tool tip when mouse is entered onto it.
    I'm using java.awt.container not Jcontainer.
    I have searched in SDN forums and after reading some of the comments what I understood is �disabled Swing button can react to Mouse events but a disabled awt button can not react to mouse events�.
    Is that true or did I not understand correctly?
    And how would I be able to implement the required functionality in my
    application?
    Thanks.

    import java.awt.*;
    import java.awt.event.*;
    public class AwtTooltip {
        private Panel getContent(Frame f) {
            Button left = new Button("left");
            left.setEnabled(false);
            Button right = new Button("right");
            Panel panel = new Panel(new GridBagLayout());
            new TipManager(panel, f);
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.weightx = 1.0;
            panel.add(left, gbc);
            panel.add(right, gbc);
            return panel;
        public static void main(String[] args) {
            AwtTooltip test = new AwtTooltip();
            Frame f = new Frame();
            f.addWindowListener(closer);
            f.add(test.getContent(f));
            f.setSize(300,100);
            f.setLocation(200,200);
            f.setVisible(true);
        private static WindowListener closer = new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
    class TipManager extends MouseMotionAdapter {
        Panel component;
        Window tooltip;
        Label label;
        public TipManager(Panel panel, Frame frame) {
            component = panel;
            panel.addMouseMotionListener(this);
            initTooltip(frame);
         * Since enabled Buttons consume MouseEvents we will
         * receive events sent only from disabled Buttons.
        public void mouseMoved(MouseEvent e) {
            Point p = e.getPoint();
            boolean hovering = false;
            Component[] c = component.getComponents();
            for(int j = 0; j < c.length; j++) {
                Rectangle r = c[j].getBounds();
                if(r.contains(p)) {
                    hovering = true;
                    if(!tooltip.isShowing())
                        showTooltip(c[j], p);
                    break;
            if(!hovering && tooltip.isShowing()) {
                tooltip.setVisible(false);
        private void showTooltip(Component c, Point p) {
            String text = ((Button)c).getLabel();
            label.setText(text);
            tooltip.pack();
            convertPointToScreen(p, component);
            tooltip.setLocation(p.x+10, p.y-15);
            tooltip.setVisible(true);
        /** Copied from SwingUtilities source code. */
        public void convertPointToScreen(Point p, Component c) {
            Rectangle b;
            int x,y;
            do {
                if(c instanceof Window) {
                    try {
                        Point pp = c.getLocationOnScreen();
                        x = pp.x;
                        y = pp.y;
                    } catch (IllegalComponentStateException icse) {
                        x = c.getX();
                        y = c.getY();
                } else {
                    x = c.getX();
                    y = c.getY();
                p.x += x;
                p.y += y;
                if(c instanceof Window)
                    break;
                c = c.getParent();
            } while(c != null);
        private void initTooltip(Frame owner) {
            label = new Label();
            label.setBackground(new Color(184,207,229));
            tooltip = new Window(owner);
            tooltip.add(label);
    }

  • Disabled buttons still generate events

    It seems that disabled buttons still generate events in business one. If a button is disabled (even a standard one) click events can still be seen in the SBO event logger. I would have expected a disabled button to be completely disabled and no events to be generated whereas as it is I have to check in the event handler to see if the button is enabled or not.
    Is my understanding of this correct?
    Has anyone else had issues like this?
    Gordon Wood

    Hi Gordon,
    That sounds like an issue with the SBO Event Logger because no event is actually triggered in the addon when the button is disabled.
    Kind Regards,
    Owen

  • Another JTable/buttons in cells query - event forwarding

    Hi Everyone.
    Apologies in advance for yet another thread on this subject. I realise this has been discussed a number of times but I can't find what seems like a definitive solution.
    I understand what the fundamental issue is with putting JComponents in table cells - i.e. that the cells are rendered essentially as static visual entities, that they're not "components" as such and will not receive events.
    I'd like to implement JButtons in table cells so that they behave as "normally" as possible - i.e. handle their own roll-over appearance, handle their own pressed appearance, and fire action events when pressed, with as little manual intervention in these mechanisms (e.g. in mouse listener code) as possible. I'm trying to do this by forwarding mouse events from the table to the button, but this doesn't seem to work as I'd hoped and I have various questions...
    (Background: I have implemented JButton objects in the data model, and the getTableCellRendererComponent() method returns *(JButton)value*.)
    My first question concerns the interception of mouse events. The usual technique would be to add a mouse listener and/or mouse motion listener to the table, and implement mouseClicked(), mousePressed() etc. However, can I override the table's processMouseEvent() and processMouseMotionEvent() methods instead, and from here forward events to buttons where appropriate, or process normally with super.processMouseEvent()? My motivation for doing this would be specifically not to invoke the super methods where events were forwarded to buttons - effectively consuming the event. Is this correct technique?
    My second question concerns attempts to reproduce button roll-over appearances. The JTable is of course considered a single entity as far as mouse events are concerned, and MOUSE_ENTERED and MOUSE_EXITED events aren't generated as the pointer moves from cell to cell. Merely forwarding mouse events to buttons - which will mostly be MOUSE_MOVED events - seems to be insufficient and presumably the roll-over appearance change relies upon ENTERED and EXITED events occurring at the proper times.
    I mimicked this behaviour in my override of processMouseMotionEvent() by calculating the value (i.e. JButton reference) of the cell under the mouse pointer, and if it wasn't the same as for the previous event, manually creating a MOUSE_ENTERED event and forwarding it to the new button. This seemed to work - the rollovers were happening (provided a table repaint() was performed), but it seemed to work without needing to explicitly sending a MOUSE_EXITED to the previous button before sending MOUSE_ENTERED to the new. I'm unclear why this is so - I was half-expecting both buttons to acquire the roll-over state, and they didn't.
    Also, I had assumed that having taken care of this, I should forward MOUSE_MOVED events occurring within the confines of a cell's area to the button verbatim, but this seems to instantly cancel out any roll-over (visually the button would briefly flash a roll-over appearance as the pointer moved into its cell bounds). Why might this be so?
    My last question is about the actual pressing of the button. I had hoped that forwarding MOUSE_CLICKED, MOUSE_PRESSED and MOUSE_RELEASED would cause the button to (a) acquire the button-pressed state, and (b) fire an action event to its action listeners. Neither of these things occur, and I don't understand why not.
    In summary, is interception and forwarding of events like this a viable technique for implementing table cell buttons? The various solutions that a Google trawl throws up all reproduce button-pressing mechanics in varying degrees, some just detecting a click and calling some user function, others manually manipulating the button model in the mouse handler etc. If possible I'd like to avoid this, and leave as much processing as possible to the button's native code.
    Thanks in advance for any suggestions received.
    Regards,
    A.

    try to look on this
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editrender

  • Event in case structure

    Dear all,
    I am using Event Structure in a Tab Control.
    On page 1, there is a Table Control and when the mouse is clicked on it, it returns the Cell Value. The event is working ablsolutely fine, but the problem is i have no idea how to Stop the Event.
    I am attaching my Vi here. Pls have a look at it and let me know of a possible solution.
    Thanks,
    Ritesh
    Solved!
    Go to Solution.
    Attachments:
    Event in Tab.vi ‏18 KB

    ritesh024 wrote:
    But, it means that the Events in Page 1 are getting triggered even when the Control is on Page 2.
    That would take the unnecessary memory and time as there is no need for the events on Page 1 to run when the Control is on a different page.
    No, the event will not get "triggered", because if you are on the other tab it is impossible to fire the table event and a mouse up cannot occur. The event structure is in memory no matter what and placing it inside a case structure only complicates the code and can will lead to problems.
    The event structure should always be in the dataflow, the tab position is irrelevant. Never hide an event structures inside a case structure!
    Here's a quick example (LV 8.5). Tab 1 has your table and senses the cell position. Tab 2 has a light switch. As you can see there is no case structure needed.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Event_in_TabMOD.vi ‏19 KB

  • IOS Home Button and Event.ACTIVATE/Event.DEACTIVATE

    Hi all,
    I read tons of questions re iOS Home Button and Event.ACTIVATE/Event.DEACTIVATE. Everything should work well if you set the proper listeners and save/restore your app state upon receiveing these events.
    My question is: Is there a way to tell difference between a Home Button press and an iOS notification alert or incomming call? In both cases, AIR will dispatch Event.DEACTIVATE, however I want to know if the user pressed the Home Button or if he just received an SMS/Calendar alert, and adapt my app state accordingly - i.e. if it's a Home Button press, change my app state to "Main Menu", otherwise (SMS/Calendar/alert) I will pause execution.
    NOTE: I don't want to override the Home Button behaviour, just want to tell if it's a Home Button press or SMS/Calendar/alert, and react accordingly. The iOS documentation states that in case of SMS/Calendar/alerts, (void)applicationWillResignActive:(UIApplication *)application is dispatched, and in case of actually going to background state (i.e. Home Button pressed) (void)applicationDidEnterBackground:(UIApplication *)application is dispatched.
    Thanks

    Any luck with this yet? I'm having the exact same issues but on a different device, the Kindle Fire.
    I need to determine whether a user hit the Home button, or hit the Quick Settings button (that accesses controls like volume). Air treats both events equally by broadcasting Event.DEACTIVATE. Unfortunately, the Amazon Appstore approval team thinks otherwise...
    It seems like there should be a simple, no-brainer way to track these events, but I'm beginning to suspect Air just is not capable. In that case, if you're developing for Kindle Fire, you may want to avoid going with Adobe.

  • Creating a new Event in event structure

    Hi
    Can i create any event on my own in the event structures? For instance, one can always find the key down and key up events in the structures!!
    But what if i want to create a new event such as add/remove hardware in it? Is it possible?
    Somil Gautam
    Think Weird

    Hi Somil,
    see the attached picture as an example.
    If you use LabVIEW 2009, then you should be able to insert the picture into your vi, to get the code.
    Mike
    Attachments:
    Event2.PNG ‏23 KB

  • How to disable registration for a past event

    Hello community,
    Please help.
    I know I've seen something written or a tutorial on how to make past events disabled for registration in the events module, but now I can't find them to save my life. It seems obvious that this should be the default situation (what business in the world wants to allow users to register for a past event?), but I'm willing to make mods until Adobe figures this out.
    Please tell me this is possible. And PLEASE let it not be a massive hassle! My client has daily events (basically daily admission) and creating each day separately is already a hassle after I sold them on BC functionality. For them to have to delete each event daily so that (their often elderly) personage won't get the day wrong and purchase for a past date is something I don't want to tell them they have to do.
    I'm using a modified web form with payment to allow multiple registrations.
    Thank you in advance!

    Your sister needs to disable iMessage on her iPhone if the iPhone is still available if she hasn't already done so.
    If she has, does she have iMessage enabled with the same Apple ID on another iOS device or on a Mac as was used to activate iMessage on her iPhone?

  • JTree - How do I fire a valueChange Event from a keyPressed Event?

    Hi,
    I have been stumped trying to figure out how to fire a valueChange event in my JTree from a keyPressed event.
    When a user changes tree node using the mouse a valueChange event fires. In my program the valueChange executes some code that must be done. I want to get my JTree to work, so that if a user is nagivating the tree using the keyboard, the code is only executed if they press the enter key.
    Below is a little demo program of what I am attempting to accomplish. Any suggestions would be greating appriciated.
    Thanks,
    Corey
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    public class SimpleTreeDemo extends JFrame  {
      public SimpleTreeDemo() {
      public static void main(String args[]) {
        JFrame j = new SimpleTreeDemo();
        DefaultMutableTreeNode category = new DefaultMutableTreeNode("Top of JTree");
        DefaultMutableTreeNode leaf1 = new DefaultMutableTreeNode("leaf1");
        DefaultMutableTreeNode leaf2 = new DefaultMutableTreeNode("leaf2");
        category.add(leaf1); category.add(leaf2);
        final JTree jtree = new JTree(category);
        boolean bflag = false;
        jtree.addTreeSelectionListener(new TreeSelectionListener() {
             public void valueChanged(TreeSelectionEvent e) {
                  System.out.println("valueChanged");
                  if (bflag)
                       // Execute Code
        jtree.addKeyListener(new KeyListener() {
            public void keyTyped(KeyEvent ke) {
              System.out.println("keyTyped");
            public void keyPressed(KeyEvent ke) {
                 System.out.println("keyPressed");
                 if (ke.getKeyCode() == KeyEvent.VK_ENTER)
                      bflag = true;
                    // Fire valueChanged here!
            public void keyReleased(KeyEvent ke) {
                 System.out.println("keyReleased");}
        Container c = j.getContentPane();
        c.add(jtree);
        j.setSize(200,200);
        j.show();

    Try this, it works for me.
    // Tree Key Listener
          tree.addKeyListener(new java.awt.event.KeyAdapter() {
             public void keyPressed(KeyEvent e) {
                tree_KeyReleased(e);
    private void tree_KeyReleased(KeyEvent e) {
          try {
          int keyCode = e.getKeyCode();
          // Get the Tree Path
          TreePath selPath = tree.getSelectionPath();
          if (keyCode == e.VK_DELETE) { //KeyCode - 127
             removeSelectedNode(); // Remove the node
          else if (keyCode == e.VK_ADD) { // Key Code - 107
             tree.expandPath(selPath); // Expand the Node
          else if (keyCode == e.VK_SUBTRACT) { // Key Code 109
             tree.collapsePath(selPath); // Collapse the Node
          else if (keyCode == e.VK_ENTER) {
              // What Ever you want to do here
          else {
          } catch (NullPointerException ex) {
          //System.out.println("Null");
    [/code                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to fire JComboBox itemStateChanged event manually?

    hello:
    I want to know how to fire JComboBox itemStateChanged event manually.
    thank you
    -Daniel

    Call setSelectedIndex or setSelectedItem.

  • Disabled button getting focus

    My problem is that a disabled button are getting focus, which is bad when the application are operated without a mouse.
    I made this litlte demo to illustrate the problem.
    Try pressing button no.1. This will disable button no.1 and button no.2,
    but why are button no.2 getting focus afterwards?
    * NewJFrame.java
    * Created on 29. september 2005, 16:55
    import javax.swing.*;
    * @author  Peter
    public class NewJFrame extends javax.swing.JFrame {
        /** Creates new form NewJFrame */
        public NewJFrame() {
            initComponents();
            printButtonStatus();
        private void printButtonStatus () {
            printFocus (jButton1);
            printFocus (jButton2);
            printFocus (jButton3);
            printFocus (jButton4);
         * Just debug inf.
        private void printFocus (JButton button) {
            System.out.println ("Button=<" + button.getText () + ">, Enabled=<" + button.isEnabled() + ">, Focus=<" + button.isFocusable() + ">");
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            jPanel1 = new javax.swing.JPanel();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            jButton3 = new javax.swing.JButton();
            jPanel2 = new javax.swing.JPanel();
            jButton4 = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jButton1.setText("jButton1");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
            jPanel1.add(jButton1);
            jButton2.setText("jButton2");
            jPanel1.add(jButton2);
            jButton3.setText("jButton3");
            jPanel1.add(jButton3);
            getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
            jButton4.setText("jButton1");
            jPanel2.add(jButton4);
            getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
            pack();
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:       
            jButton1.setEnabled(false);
            jButton2.setEnabled(false);
            jButton3.setEnabled(false);
            printButtonStatus();
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame().setVisible(true);
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton3;
        private javax.swing.JButton jButton4;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        // End of variables declaration
    }

    Very courius.
    I have made a little change in your code.
    1) scenario
    Simply changing .setEnabled(false) invokation, the class works fine.
    so
    jButton2.setEnabled(false);
    jButton3.setEnabled(false);
    jButton1.setEnabled(false);
    2) scenario
    the class works fine also using your .setEnabled(false) order invokations and putting after those:
    FocusManager.getCurrentManager().focusNextComponent();
    I do not know exactly why, I suppose that is there something not properly
    syncronized in events dispaching.
    In my opinion:
    a) setEnabled(false) at last calls for setEnabled(false) of JComponent
    that fires a propertyChange event
    so:
    scenario 1)
    buttons 2 and 3 are disabled before of button1 that has the focus in
    that moment (given by a the mouse click on itself)
    When botton1.setEnabled(false) is performed buttons 2 and 3 are
    just disabled, so focus is got by button4 (that is enabled)
    scenario 2)
    button1 that has the focus (given it by the mouse click) becames
    disabled before that button2 becames disabled too.
    So, probably, when the event of PropertyChanged is fired and processed, button2.setEnabled(false) invokation has not been
    just performed and swings looks for it as a focusable component
    So, using FocusManager.getCurrentManager().focusNextComponent(),
    we force the transer focus on next focusable component.
    This is only a my suppose, looking what happens.
    Regards.
    import javax.swing.*;
    * @author Peter
    public class NewJFrame extends javax.swing.JFrame {
    /** Creates new form NewJFrame */
    public NewJFrame() {
    initComponents();
    private void printButtonStatus () {
    printFocus (jButton1);
    printFocus (jButton2);
    printFocus (jButton3);
    printFocus (jButton4);
    System.out.println("--------------------------------");
    * Just debug inf.
    private void printFocus (JButton button) {
    System.out.println ("Button=<" + button.getText () + ">, Enabled=<" + button.isEnabled() + ">, Focus=<" + button.hasFocus() + ">, Focusable=<" + button.isFocusable() + ">");
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    private void initComponents() {
    jPanel1 = new javax.swing.JPanel();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jButton3 = new javax.swing.JButton();
    jPanel2 = new javax.swing.JPanel();
    jButton4 = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jButton1.setText("jButton1");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton1ActionPerformed(evt);
    jPanel1.add(jButton1);
    jButton2.setText("jButton2");
    jPanel1.add(jButton2);
    jButton3.setText("jButton3");
    jPanel1.add(jButton3);
    getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
    jButton4.setText("jButton1");
    jPanel2.add(jButton4);
    getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
    pack();
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    // I have simply change the order
    jButton2.setEnabled(false);
    jButton3.setEnabled(false);
    jButton1.setEnabled(false);
    // with this sentence the class work with original .setEnabled order
    //FocusManager.getCurrentManager().focusNextComponent();
    SwingUtilities.invokeLater(new Runnable()
    public void run()
    printButtonStatus();
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new NewJFrame().setVisible(true);
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration
    }

Maybe you are looking for