Handling JCheckBox events

Hello,
I need to implement a JCheckBox event handler that only runs its code when the user herself selects and unselects it. I used an ItemListener handler. My problem is that now whenever I change the selection of this JCheckBox programmatically using the setSelected(boolean) method, it also runs the method of the ItemListener event handler !! How can I tell Java to run the handler only when the user produces the event? I read the setSelected(boolean) method specification and I think that it will not be called programmatically only if I handled the JCheckBox with an ActionListener handler, but is there a way to achieve the same thing with an ItemListener handler?
Thanks in advance

camickr wrote:> > And why would you retrieve the model when you can check the check box directly?To tell you the truth, I have never used an ActionListener to handle a JCheckBox before as I use it to deal with JButtons most of the time. But the following is taken from a well known book on Java Swing:
Listening to JCheckBox Events with an ActionListener:
Subscribing to ActionEvent generation with an ActionListener allows you to find out when the user toggles the state of the JCheckBox. As with JToggleButton, the subscribed listener is told of the selection, but not the new state. To find out the selected state, you must get the model for the event source and ask_, as the following sample ActionListener source shows. This listener modifies the check box label to reflect the selection state:
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
AbstractButton abstractButton = (AbstractButton)actionEvent.getSource();
boolean selected = abstractButton.getModel().isSelected();
String newLabel = (selected ? SELECTED_LABEL : DESELECTED_LABEL);
abstractButton.setText(newLabel);
camickr wrote:Well, it already does. Apparently, the ItemListener is fired when the model changes, but the ActionListener only fires when the button is clicked. So how does this not meet your criteria, if you use the ActionListener?The question was how to meet the criteria with the use of an ItemListener handle, not an ActionListener. According to the Java API documentation, The method setSelected(boolean)* does not trigger an <code>actionEvent handler, but it indeed triggers an ItemListener handler as this is my problem that I face in my code. However, the Java API offers an altenative method to setSelected(boolean)* that will trigger an ActionListener handler if we want to handle a JCheckBox element programmatically, which is the doClick* method. Now the question is: Is there any alternative method to setSelected *that will NOT trigger the ItemListener handler? </code>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Event handler : handleEvent(Event event)

    Good day,
    The deprecated event handler "handleEvent(Event event)" has been replaced by "processEvent(AWTEvent event)" as per the docs.
    With some research, I came up with this little conversion chart :
    item handleEvent processEvent
    ====== ============ ============
    x event.x event.getX()
    y event.y event.getY()
    id event.id event.getID()
    target event.target ???
    ====== ============ =============
    I'm just trying to compile a list of conversion for deprecated APIs with some extra information to "ease" the transition process.
    Is the above information right or am I still missing the boat ?
    Please apply necessary corrections wherever applicable.
    Best regards.

    Good day,
    The deprecated event handler "handleEvent(Event event)" has been replaced by "processEvent(AWTEvent event)" as per the docs.
    With some research, I came up with this little conversion chart :
    item handleEvent processEvent
    ====== ============ ============
    x event.x event.getX()
    y event.y event.getY()
    id event.id event.getID()
    target event.target ???
    ====== ============ =============
    I'm just trying to compile a list of conversion for deprecated APIs with some extra information to "ease" the transition process.
    Is the above information right or am I still missing the boat ?
    Please apply necessary corrections wherever applicable.
    Best regards.

  • Is it possible to handle multiple events using Jscript for a button in Apex

    Hi,
    I've application wherein in one of the pages for a button, I need to trigger 2 events as: 1. redirect to a new page upon 'click' of the button
    2. display a set of values on 'mouse over' that button.
    I'm able to handle both separately, but not in one button. I would like to know if there is any limitation in Apex that we cant handle multiple events? Currently I've put a text item near the button, and called the Jscript for mouse over event in that as a temporary workaround. Can someone let me know if this is feasible? If not any other alternative to handle this?
    Thanks in advance,
    gsachidh

    Hi Gsachidh,
    well interesting problem you're facinng. Indeed, it can't be specified using the 'Button Attributes' So we have to come up with an workaround.
    A quick en dirty solution would be to specify it with the 'Optional URL Redirect options'. In a normal button, with processing on same page, this would be 'no target'. but in case of additional things to be done this can be used, using an target URL. I used this many times, in example with popUp windows for refreshing the caller object when changes are made. In your case we have to add next to the href an onmouseover event. this can be done with;
    Target set to => URL
    URL - target => javascript:doSubmit('<button_name>');" onMouseOver="javascript:showTooltip('tooltip');"
    Here the " is the key, letting ApEx know the target (href) is doSubmit('<button_name>'), just like when no target would be specified and adding a new javascript event; onMouseOver.
    Although this is a dirty solution in my opinion, it is the best i could come up with. I have another idea in how to do this, that is by adding this event dynamically with javascript with an addEvent. But i don't have an example at the moment for this scenario.
    Simon
    Message was edited by:
    S1M0N

  • Reg : Cross browser issue while handling LOV event on KeyFlexFeild

    Hi OA Gurus,
    We are encountering issues on R12.0.6, JDev 120Rup6.
    We have the following test case and code changes.
    Requirement:
    We have OA page where we have one KeyFlexFeild item and a normal LOV. Page items are part of one AM and LOV is in another AM.
    The requirement was to make LOV dependent on keyFlexfeild. Test case is mentioned as per following flow.
    1.     User changes cost center segment of Accounting Flex(Key flex) using Cost center LOV.
    2.     Another LOV in the same page should be dependent on new value of cost center as modified in step 1.
    Solution Implemented:
    Describing in the 3 steps
    1) Here the KeyFlexFeild is expense account. Whenever User changes any segment, we handle
    ‘lovValidate’ and ‘lovUpdate’ events on KeyFlexFeild in processFormRequest of controller.
    2) Retrieve the value of cost center segment using getSegmentsQualifiedBy(), Update corresponding VO attribute of the LOV query parameter.
    3) Forward the request to current page so that LOV will have modified value with updated query.
    4) Forwarding to current page is must because LOV is built with another AM and will loaded only when page is built.
    Issue:
    This works fine on internet explorer. When trying to run the same in Mozilla we have following issue
    1) User modifies one of the segments of expense account and make a tab – out
    2) Now the page refresh happens
    3) Now in the same page no other LOV or no other button works. He can’t click on any button for submit or cancel.
    LOVs will not open even after clicking on it.
    Code changes:
    //Step1 – Handle LOV events
    String source = pageContext.getParameter(SOURCE_PARAM);
    String eventType = pageContext.getParameter(EVENT_PARAM);
    if(source !=null && eventType != null) {
    if(source.startsWith("Acct") && eventType.equals("lovUpdate") || eventType.equals("lovValidate") ) {
    KeyFlexfield flex = (KeyFlexfield)lkff.getAttributeValue(OAWebBeanConstants.FLEXFIELD_REFERENCE);
    // Step -2 Updating the corresponding VO attribute for LOV to get the modified the value
    Segment[ ] segmentL = flex.getSegmentsQualifiedBy(FA_COST_CTR");
    CostCenterValue = segmentL[0].getValue().getValue();
    if(CostCenterValue != null ){
    sampleViewObject.getCurrentRow().setAttribute("ToCostCenter",CostCenterValue);
    OAFormValueBean formValueBean = (OAFormValueBean)webBean.findIndexedChildRecursive("ToCostCenter");
    if(formValueBean != null)
    formValueBean.setValue(pageContext, CostCenterValue);
    OAMessageLovInputBean formValueBean1 = (OAMessageLovInputBean)webBean.findIndexedChildRecursive("ReceivingApprover");
    if(formValueBean1 != null)
    formValueBean1.setValue(pageContext, null);
    else
    sampleViewObject.getCurrentRow().setAttribute("ToCostCenter",null);
    //Step 3 – Forward the request Current Page again
    pageContext.setForwardURLToCurrentPage(null, true, ADD_BREAD_CRUMB_YES, (byte)0);
    We have following questions.
    a)     Solution implemented by us is correct ? or we have to implement it in another way ?
    b)     Is OA version mentioned above supported on Mozilla browser version 3.x ? This issue is not occurring on Mozilla 1.x while running from JDev.
    Please let us know if any additional details required.
    Thanks for help in advance.
    Edited by: user774130 on Dec 15, 2009 2:27 AM

    Hi,
    It seems that you have not noticed that this forum is not for posting product-related questions/problems....
    So , this might be the correct forum....
    Java Server Pages (JSP)
    Sim

  • How to handle softkey events

    hi all,
    The softkeys varies form device to device.so kidly say some genric way to handle softkey events.
    Thanks in advance
    Badri

    The only "generic" way to handle softkeys is to use Commands.
    shmoove

  • Javascript error in event handler! Event Type = element [edge.2.0.0.min.js:162]

    I'm doing a little edge project (now in beta version) for my girlfriend (she hates the code), with examples of the animate() method and other functions like setInteval(), but when I run I get the following error in Chrome console:
    Javascript error in event handler! Event Type = element [edge.2.0.0.min.js:162]
    But this library is global for all projects, how is possible that trigger an error?
    Example here:
    https://app.box.com/s/m7nof4al6597gfn47jlu
    Thanks.

    you dont need to import java ease !!
    it's already included in edge animate, remove that yepnope completely your problem will gone
    Zaxist

  • Handling Key Event

    How to handle key events in the Console?
    Plz give sample code for it.
    Thanks in advance.

    Don't have any experience with it personally, but I think curses does this type of thing http://sourceforge.net/projects/javacurses/

  • Handling Button Event

    Hi all,
    i am using a 'When-Validate-item' trigger in this i am doing a validation,
    when user try to enter amount greater than the given amount(This is needed validation)
    and also i am regenerating new lines(Creating new records when button pressed)
    when i am regenerating i should not validate.
    How to handle button event
    Thnx
    Raj

    Hi...
    The WHEN-VALIDATE-ITEM Trigger fires once you updated a field. Be sure you raise
    form_trigger_failure when amount is invalid. So, the cursor stays in field amount. You cant
    leave this field until the amount is not valid.

  • How to handle Valuechange events, when page bean is in request scope

    Hello balusc and forum mates,
    I want to know is there any good way to handle ValueChangeEvents events, when the page's bean in request scope.
    My problem is, I have a page having more than 1 value change event so How can I maintain page values at backing bean. My bean is request scope, I can't change to session scope.
    Please I really need it.

    Hi Frank...
    In my code i used almost same logic as Andrejus Baranovskis has explained in his Editable Table example...
    You can refer that example to see what problem I'm facing...
    http://andrejusb.blogspot.com/2007/04/create-edit-and-delete-operations-in.html
    The Bean Scope in this Example is Session scope...Save button is working fine...
    But as i Change the bean scope to Request scope then Save button is not working for Edit but it is working for Delete Action very well..
    I want that save button should work also for Edit action in Request Scope..
    Please Make me understand that why it is happened like that..
    and help me to find the solution..
    and Also if you have a better document to Explain the life cycle of Application in Different Bean Scope...So please provide me that Doc to me...
    It would be a great help for me to understand the concept of session...
    Thanks Frank
    Fizzz...

  • Best way to handle an event from WaitForSingleObject

    Hello LV experts,
    I would like to know what's the best way to handle an event which I catch using the Win32 API (WaitForSingleObject) in Labview(7.1 or 8.20).
    I know there is too many possibilities to do this, but I want to do it  on the best way. that is why I would like to have ideas and tips from you.
    Any and all tips appreciated

    You can download the Library from this link. Inside is an example that shows how to handle windows messages/events.
    http://zone.ni.com/devzone/cda/epd/p/id/4394

  • Handling FPM Events in Java WDP

    Hi All,
    I have a requirement for a simple WDPJ iView that responds to the selection of an employee in MSS.
    Is it possible to handle the employee selection event from Business Package for Manager Self-Service (mySAP ERP) from a simple WDPJ iView that is not configured/resgistered as an FPM Self-Service application?
    Can a WDPJ simply handle theses events if the event name is known?
    Cheers,
    Steve

    Steve,
    you may want to check out these links
    Adding custom iview to general info
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/profile/how-toaddacustomWebDynproiViewtotheMSSEmployeeProfile%28ECC+6.0%29
    and check this note 1112733
    Thanks
    Bala Duvvuri

  • Handling button events in large app

    I'm currently examining a large swing app, and have observed the following with regard to action events.
    A number of listeners (for buttons, menu items, JLists etc.) are defined at the top of the app. These variously extend MouseAdapter or implement ActionListener, depending on the type of component whose actions they listen for.
    The ButtonListener definition is as follows :
    private class ButtonListener implements ActionListener
    public void actionPerformed(ActionEvent event)
    Object object = event.getSource();
    if (object == button1)
    // button1 actions
    else
    if (object == button2)
    // button2 actions
    .....etc
    One instance of this listener is created in the app, and is used as the actionlistener for each button. This means that the buttonlistener is quite large (as it contains the code for each button in the app).
    Is this the proper way to handle button events for an app with a large number of buttons?

    Thanks for the responses.
    In response to theDude : I agree that defining the action listener for each button can be useful when you can see the button definition and button action in one place; one could counter that by saying that grouping all the button actions makes it easier to examine all button actions in one place.
    Setting the action command isn't really an option because the application creates panels of buttons on the fly, e.g. when notification of a new customer is received, a new panel is created with a JTextPane (customer description) and a row of buttons for "Modify", "Delete" and "Print".
    Several customer panels could be in existence at the same time, so setting an action command of "Modify" would not enable one to uniquely identify which "Modify" button was pressed.
    This problem is currently handled by associating the panel instance with a "Customer" class instance in a hashtable. The "Customer" class consists of a JTextPane field, and a JButton for each function. When a button is pressed, the button listener traverses up the component's parents until it reaches the panel (i.e. it loops until the parent is a key on the hashtable, at which point it can retrieve the Customer instance and check which button was pressed).
    In response to KPSeal : If I understand you, I would define "ApplicationAction" separately from the main app and define extensions of it in the main app for each type of action. Would this add much value over merely defining a method for each type of action in the main app and just calling this method when the relevant button/menu item was pressed/selected?
    There doesn't seem to be a universal approach to event handling, but I thought there might have been one accepted strategy when an app has large numbers of buttons (some created on the fly, ruling out action commands).

  • Handling keyboard events in applets?! Possible?!

    Hello,
    I wrote a little game that uses keyboard handling events. It is an applet that can also standalone as an application. When i run the program as a standalone application, it handles keyboard inputs fine. ie...i can press the left and right arrow keys and something happens.
    But when i run my program as an applet in a web browser, the applet starts up correctly but does not handle any keyboard events. It only handles mouse events. For instance, if i press the up and down arrow keys, the browser window scrolls up and down!!! And the up and down arrow keys have a specific purpose in my applet.
    QUESTION: how do i get my applet to accept keyboard inputs such as UP,DOWN, LEFT, RIGHT?

    Hmm something went wrong w/ my post so i hope this doesnt show up twice.
    Hey thanks a lot for helping me out. The applet/application is large so here is the main() method and the keyboard event handling class code. My question is how come the keyboard events get properly handled when i run it as a standalone application, but keyboard events go to the browser when i run it as an applet? I would post my entire code but it's over 1000 lines and spread out over 8 files. hehehe.
    Here is main():
      public static void main(String[] args)
          MyProgram applet = new MyProgram();
          applet.isStandalone = true;
          JFrame frame = new JFrame();
          frame.setTitle("Physics: Kinematics");
          frame.getContentPane().add(applet, BorderLayout.CENTER);
          applet.init();                        // initialize the applet inside frame
          applet.addKeyListener(kbHandler);     // kbHandler is a keyboard handling object
          applet.start();
          frame.setSize(APPLETWIDTH,APPLETHEIGHT);
          Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
          frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
          frame.setVisible(true);
          // private inner class to terminate the Application when frame closes
          frame.addWindowListener(
            new WindowAdapter()
                public void windowClosing(WindowEvent e)
                    System.exit(0);
          frame.show();
       }"kbHandler" is the keyboard event handling object. It gets initialized in the applet.init() method.
    kbHandler = new BMkeyboardHandler();And here is the keyboard event handling code:
    // ===== keyboard event handler ===========
       private class BMkeyboardHandler implements KeyListener
            public void keyPressed(KeyEvent e)
                pushedKey = e.getKeyCode();
                // General administrative key actions
                if(pushedKey == KE.VK_H)
                    actionArea.toggleHelpMenu();
                    actionArea.repaint();
                else if(pushedKey == KE.VK_C)
                    actionArea.toggleCtrlMenu();
                    actionArea.repaint();
         }So there it is. Again, the program handles events fine as a standalone application. But running it as an applet in a browser (and even the appletviewer) doesnt let me handle keystrokes.

  • Handling HTMLB events in BSPs???

    Hi all,
    can anybody tell me the how to handel events in BSPs??

    Hi Aravind,
    Follow the link  /people/brian.mckellar/blog/2004/07/28/bsp-programming-handling-htmlb-events u can understand.

  • Handling mouse events in JSP

    Hi ,
    I have to handle mouse events in JSP,means i have to handle the event
    of the user i.e, if he press the lest click we have to handle that
    event where he pressed it with JSP. Iam finding examples in Applets ,
    nut i have to do it in JSP.Can any body help me please? it's very
    urgent.
    Thanks in advance
    BhargavKumar.B

    JSP cannot catch mouse events. You need a clientside language for that, such as Javascript. So catch the mouse click event in Javascript, get the desired information from it and send it as request parameters to the server, so that the serverside logic can intercept on it. You can use AJAX for that, if you want to do it asynchronously.

Maybe you are looking for

  • Music files missing/hidden in folder on network hdd

    Hi all, I have setup my home net work with a iMac (mountain Lion) backed up by a TimeCapsule and at the back of the TimeCapsule I have a 2TB networked external HDD. My iTunes library is located on this HDD, I take care not to start up iTunes before t

  • HOW TO UNLOCK AN IPOD TOUCH WHEN YOU FORGOT PASSCODE

    How can I unlock my son's IPOD touch when he has forgotten his passcode?

  • SAP ECC6 IDES Activating Funds Managment

    Dear Sir, I have an issue. When i want to activate the Funds Management for the company code 1000 ( AA Derivation and Update control), the system comes up with the message "Read only access" error message no. SV044. This transaction comes up in Displ

  • Flash Player nightmare

    Problems started when i received an AVG looking virus/malewear that hijacked my ie.  Used malewarebytes program which seemed to remove the malware.  Since then I have been unable to use flash player to watch videos  or do anything which requires flas

  • Mountain Lion, Keynote & Autosave problems?

    I haven't upgraded to ML yet.  Just curious about user experiences with keynote and autosave.  When I upgraded to Lion, autosave would interrupt my typing with the "spinning wheel".  It was so disruptive to my workflow that I downgraded to the last v