Event handling between JComboBox & JCheckBox

Hi.
My problem is that when i click on the JCheckBox object, the code (i have) also executes the condition for JComboBox object. I assume there is a very simple solution, but i have yet to find it.
This is the code i'm using:
     public void itemStateChanged(ItemEvent e){
          if(qcmCheckBox.isSelected()){
               System.out.println("checkbox selected");
          if(e.getStateChange() == ItemEvent.SELECTED){
               System.out.println("combo selected " + comboBoxOptions.getSelectedIndex());
     }My problem is, i think, that the e.getStateChange() is always returning true. I just haven't figured out a way to 'single out' when the JComboBox is selected.

thanks for the tip, but that didn't exactly work.
these are my steps:
select second drop down option (out of 3)
select checkbox
deselect checkbox
old output
combo selected1
qcm selected
combo selected1new output (using instanceof)
combo selected 1
combo selected 1
checkbox selected
combo selected 1
combo selected 1here's my code:
// setting up vars
private JCheckBox checkBox = new JCheckBox();
private final String comboNames[] = {"Option 1", "Option 2", "Option 3"};
private JComboBox comboBoxOptions = new JComboBox(comboNames);
// combo box
comboBoxOptions.addItemListener(this);
// checkbox
checkBox.addItemListener(this);
// event handler
public void itemStateChanged(ItemEvent e){
     if(checkBox.isSelected()){
          System.out.println("checkbox selected");
     //if(comboBoxOptions instanceof JComboBox){ // the suggested alternative
     if(e.getStateChange() == ItemEvent.SELECTED){
          System.out.println("combo selected " + comboBoxOptions.getSelectedIndex());
}For some reason, the suggested answer gives me duplicate entries for the dropdown and it still gives me duplicate entries when i click on the checkbox.
Again, what i'm trying to do is just get the checkbox not to execute the 2nd if statement "if(e.getStateChange() == ItemEvent.SELECTED){"
I think the statement "e.getStateChange()" is returning everything true because its an event happening but i don't know a way to single the checkbox event.
I would appreciate all the help I can get. Thanks.
sijis

Similar Messages

  • Event handling of JComboBox outside a JTable

    Hi to All,
    I've a question about JTables and JComboBoxes... I'm working on a application which holds a JTable and several JButtons and JCombBoxes. When the user clicks on a cell in the JTable, this cell will get the focus and the text will be highlighted. An action will be performed when the user clicks on a JButton (this just works fine). When the user clicks on a JComboBox also an action must be performed... but this won't work. I guess it won't work because of the JComboBox will draw a popup, and this popup will be cover the cell with the focus...
    I could not catch any event of the JComboBox...
    How can I check for a click on a JComboBox when an other component (JTable cell) has the focus?
    Thnx,

    Hi Swetha,
    Button controls in a table are available only in version 2.0 of the .NET PDK.
    In order to use Button in a table and handle its events u will have to upgrade.
    Further information about using input controls in a table is available in the How to section of the PDK documentation.
    Thanks, Reshef

  • Difference in event handling between Java and Java API

    could anyone list the differences between Java and java-API in event handling??
    thanks,
    cheers,
    Hiru

    the event handling mechanisms in java language
    features and API (java Application Programming
    Features)features .no library can work without a
    language and no language has event handling built in.
    I am trying to compare and contrast the event
    handling mechanisms in the language and library
    combinations such as java/ java API.
    all contributions are welcome!
    thanks
    cheersSorry, I'm still not getting it. I know what Java is, and I know what I think of when I hear API. (Application Programming Interface.) The API is the aggregation of all the classes and methods you can call in Java. If we agree on that, then the event handling mechanisms in Java and its API are one and the same.
    So what do you want to know?
    %

  • Event Handler Between Reboot states using Powershell

    Hi,
    I need some help writing an event handler for a powershell script that would meet the following requirement:
    1.  Continue Upon a restart
    2.  Continue Upon a sleep state
    3.  Continue Upon a hibernation state.

    One way that I can see that would meed all three of your requirements is to use a permanent WMI Consumer to watch the event log for each of these type of events and then perform an action.
    http://learn-powershell.net/2013/08/14/powershell-and-events-permanent-wmi-event-subscriptions/
    It would be best to make a filter for each type of event rather than throwing all into one filter. Depending on your OS, the event IDs may be different, but it is nothing that a quick query via a search engine could find for you.
    Boe Prox
    Blog |
    Twitter
    PoshWSUS |
    PoshPAIG | PoshChat |
    PoshEventUI
    PowerShell Deep Dives Book

  • Event Handling between JPanels

    Hi everyone,
    I'm trying a three-fold assignment on java, which relates to graphs and finding strongly connected components.
    In the first part, the user can create his own graph and the program should find all SCC and display them.
    In the second part, the program creates random graphs and then finds all SCC and displays them.
    In the third part, some statistical data is to be displayed.
    So what I have done so far is that I have created a JFrame on which I have added 3 JPanels, each for every part of the assignment.
    Changing between the JPanels is done by a JTabbedPane.
    My problem lies on the second part. I've created a class called RandomGraphPanel, which extends JPanel. Then I've created two sub-JPanels,
    called RandomGraphAreaPanel, where the graph should be displayed and RandomGraphDataPanel, where the user can choose some parameters on which the random graph is based. I don't know how I can paint the graph on the first sub-JPanel, after pressing a button on the second sub-JPanel.
    I will include some code from my classes:
    public class RandomGraphPanel extends JPanel
         private JPanel graphArea;
         private RandomGraphDataPanel data;
         private RandomGraphAreaPanel area;
         public RandomGraphPanel()
              super();
              setLayout(new BorderLayout(5,5));
              data = new RandomGraphDataPanel();
              area = new RandomGraphAreaPanel();
              add(data, BorderLayout.SOUTH);
              add(area, BorderLayout.CENTER);          
         }//RandomGraphPanel constructor
    }//RandomGraphPanel class
    public class RandomGraphDataPanel extends JPanel
         public RandomGraphDataPanel()
              super();
              //part where RandomGraphDataPanel is filled with 2 JSliders and 1 JButton
         }//RandomGraphDataPanel constructor
         private class ButtonHandler implements ActionListener
              public void actionPerformed(ActionEvent event)
                   //code that is executed when the button is pressed               
              }//actionPerformed
         }//ButtonHandler private class
    }//RandomGraphDataPanel classAny help will be appreciated.
    Thanks,
    philimonas

    Probably the best way would be to somehow implement the MVC pattern here. Another way would be to move the button handling code out of the RandomGraphDataPanel class and into the RandomGraphPanel class. You could then pass the ActionListener into the RandomGraphDataPanel object by perhaps a constructor parameter, or by a separate addActionListener method that you have created. Something like so:
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JPanel;
    public class RandomGraphPanel extends JPanel
        private JPanel graphArea;
        private RandomGraphDataPanel data;
        private RandomGraphAreaPanel area;
        public RandomGraphPanel()
            super();
            setLayout(new BorderLayout(5, 5));
            // *** passing ActionListener to the data class via constructor parameter
            data = new RandomGraphDataPanel(new ButtonHandler());
            area = new RandomGraphAreaPanel();
            add(data, BorderLayout.SOUTH);
            add(area, BorderLayout.CENTER);    
        // *** move this code into this class
        private class ButtonHandler implements ActionListener
            public void actionPerformed(ActionEvent event)
                area.showGraph();  // or whatever is needed to show graph       
    }and
    //import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    public class RandomGraphDataPanel extends JPanel
        public RandomGraphDataPanel(ActionListener buttonHandler)
            super();
            JButton someButton = new JButton("Show Graph");
            someButton.addActionListener(buttonHandler);
        private class ButtonHandler implements ActionListener
            public void actionPerformed(ActionEvent event)
                //code that is executed when the button is pressed         
    }

  • Please help me.... event handling on JComboBox...

    hi all,
    I have a combobox and i want a event to be fired for a single click on the down-arrow of the JComboBox. What i mean is its not the itemListener i am looking for. Only by a click on arrow i want a even to be fired. I tried using mouselistener. But the combobox ia not listening to this event. Please tell me how to achieve this?
    thx,
    -Soni.

    thx a lot.....
    it worked :)
    Now i have one more doubt.
    I am using a scroll pane and my event on this scroll pane is like this.
    I have a text field inside the pane and when i press the up arrow of scroll pane the value(intger value) inside the text field increases and the other way for down arrow button.
    i have just replaced ur code like this,
    class ScrollUI extends BasicScrollPaneUI {
    public JButton createDecreaseButton(int i) {
    try {
         ImageIcon dayDownIcon = new ImageIcon("down.gif");
         JButton b = new JButton(dayDownIcon);
         b.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent ae) {
                   System.out.println("222");
         return b;
    } catch (Exception e) {
    e.printStackTrace();
    return null;
    and setting the UI like this:
    JScrollPane pane= new JScrollPane(pp);
    pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    pane.getVerticalScrollBar().setUI(new ScrollUI());
    but it throws error like this
    setUI(javax.swing.plaf.ComponentUI) has protected access in javax.swing.JComponent
    pane.getVerticalScrollBar().setUI(new ScrollUI());
    what is the reason?
    how to solve it...
    plss....help..
    -Soni

  • Event-Handling  Between 2 Classes

    Trying to learn where did I make a mistake!
    Here is a very simple sample code:
    2 classes (each has 1 (awt-style)Panel & 1 (awt-style) Button. By clicking on one of the buttons how do I change the Background (color) of the Panel in the other class?
    //***********Sample Code **********************
    import java.awt.*;
    import java.awt.event.*;
    //=====================================================
    public class App extends Frame
    Panel_1 ap1; //ap1 --> additional panel #1
    Panel_2 ap2;
    public App()
    setLayout(null);
    setBounds(100,100,300,200);
    setBackground(Color.yellow);
    //re: Panel_1
    //=============
    ap1=new Panel_1();
    add(ap1);
    //re: Panel_2
    //===========
    ap2=new Panel_2();
    add(ap2);
    public static void main(String[] args)
    App app=new App();
    app.setVisible(true);
    //==============================================================
    class Panel_1 extends Panel implements ActionListener
    Panel_2 p2;
    Button ap1b=new Button();
    Panel_1()
    setBounds(50,120,100,50);
    setBackground(Color.green);
    ap1b.setBackground(Color.red);
    ap1b.addActionListener(p2);
    add(ap1b);
    public void actionPerformed(ActionEvent ae)
    if (ae.getSource()==p2.ap2b)
    System.out.println("Test Panel 1");
    //=================================
    class Panel_2 extends Panel implements ActionListener
    Panel_1 p1;
    Button ap2b=new Button();
    Panel_2()
    setBounds(50,30,200,50);
    setBackground(Color.orange);
    ap2b.setBackground(Color.red);
    ap2b.addActionListener(p1);
    add(ap2b);
    public void actionPerformed(ActionEvent ae)
    if (ae.getSource()==p1.ap1b)
    System.out.println("Test Panel 2");
    }

    There are several ways to do this. Without going into all of them, let's narrow them down by thinking in terms of design. Why should the panels know anything about each other? Each panel is its own deal. The component which has both of the panels should be the one listening to the buttons.
    Really there is no reason to have separate classes for the panels, but if you must, then write a listener as an inner class of the frame class, then pass that listener to the constructor of each panel as you instantiate it. Then you can have the listener work with both panels directly.
    Drake

  • Differnence between two codes of event handling

    hello i am learning event handling in swing but confused between two codes :-
    the first code of event handling is given in book "head first java " and working fine
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Swingdemo implements ActionListener {
        JButton jbut = new JButton("Click me");
          public void go(){
            JFrame jfrm = new JFrame(" sample swing");
            JLabel jlab = new JLabel("hello Swing");
            jfrm.add(BorderLayout.NORTH,jlab);
            jfrm.add(BorderLayout.CENTER,jbut);
            jfrm.setVisible(true);
            jbut.addActionListener(this); 
            jfrm.setSize(100,100);
            jfrm.setDefaultCloseOperation(jfrm.EXIT_ON_CLOSE);
       public static void main(String[] args) {
            Swingdemo obj = new Swingdemo();
            obj.go();
    public void actionPerformed(ActionEvent e)
        jbut.setText("i have been clicked");
    }}THe second code which i think is fine is giving the following error :-
    C:\java\iodemo\src\Swingdemo.java:26: non-static variable jbut cannot be referenced from a static context
            jfrm.add(BorderLayout.CENTER,jbut);
    C:\java\iodemo\src\Swingdemo.java:28: non-static variable this cannot be referenced from a static context
            jbut.addActionListener(this); 
    C:\java\iodemo\src\Swingdemo.java:28: non-static variable jbut cannot be referenced from a static context
            jbut.addActionListener(this);  the second code is as follows :-
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Swingdemo implements ActionListener {
    public static void main(String[] args) {
    JFrame jfrm = new JFrame(" sample swing");
    JLabel jlab = new JLabel("hello Swing");
    jfrm.add(BorderLayout.NORTH,jlab);
    jfrm.add(BorderLayout.CENTER,jbut);
    jfrm.setVisible(true);
    jbut.addActionListener(this);
    jfrm.setSize(100,100);
    jfrm.setDefaultCloseOperation(jfrm.EXIT_ON_CLOSE);
    JButton jbut = new JButton("Click me");
    public void actionPerformed(ActionEvent e)
    jbut.setText("i have been clicked");
    Plz help me wat this error means that not static variable cannot be reffered from static context .
    thanks

    There are multiple problems in your 2nd set of code. You call this:
    jfrm.add(BorderLayout.CENTER,jbut);
    Before you actually create the jbut button:
    JButton jbut = new JButton("Click me");
    But based on the error message, you have another 'jbut' variable somewhere that's not included in the code you posted, and that's the one it's complaining about being referenced in a static context.
    The problem with the static context is because all your code is in the static void main method. In that method, a Swingdemo instance doesn't exist yet, therefore any non-static variables won't exist yet either. If you move all that code into the Swingdemo constructor, and just have main create a new Swingdemo instance, that should do it.

  • What's different between event handle by bsp frame & MAC

    Hi,
    Can anyone know the different between event handle by BSP frame & handle by MAC?
    and how to know which event is handle by BSP frame or MAC?
    thanks
    Gang

    Hi Abdul,
    So that means the add_entry event is standard event handle by BSP frame.
    thanks
    Gang

  • Difference between method,event handler,supply function.

    hi,
    i wants to know what is the difference between
    method.
    event handler.
    supply funciton.
    Regards:
    Pankaj Aggarwal

    Hi Pankaj,
    These are few lines from the F1 help documentation given,
    Web Dynpro: Method Type :The type of a method defines whether you have an event handler, a supply
                                                function, or a (normal) method.
      Event Handler : Handlers of an event, a controller, an action, or an inbound plug of a view.
       Method : Modularization unit within a view or a controller.Methods of a view can only be called locally
                       within this view.Methods of a controller (component or custom controller) can also be called from
                       a view or another controller, provided the controller is entered as controller used .
       Supply Function : Method for filling a context node.
    For more information refer to the Thomas post
    Regards,
    Sravanthi

  • Multiple JComboBox Event Handling Problem

    Hi, guys
    I am a newbie in Java. I need to create three JComboBox, say date, month and year and a JButton "submit". After I select the entries from the three JComboBox, I click the "search" button to display something in terms of the information I selected, but I have no idea how to write the actionPerformed( ActionEvent evt) to deal with the problem. Can anyone give me some hint?
    Any help would be appreciated.

    If you are asking how to write a basic event handler for when your button is pressed, RTM.
    http://java.sun.com/docs/books/tutorial/uiswing/events/index.html

  • Event Handling of 2 JComboBoxes in 1 Frame

    Hello,
    thank you very much for your help in the following problem:
    problem: Differntiating events of 2 JComboBoxes in 1 JFrame.
    solution trial: differentiating via information of an Event-object ("list0","list1"). This solution works as stand-alone Frame, but integrating it in menu of another Frame the List-Information turns dependent on the frequency of clicking the JComboBoxes to "list2", "list3",...
    Object o = Event.getSource();
    String ComboInf = String.valueOf(o);
    ComboInf=ComboInf.substring(14,19);//here the 2 ComboBoxes are differentiated
    if(ComboInf.equals("list0")//only works for stand-alone Jframe
    -->ComboBox1
    if(ComboInf.equals("list1")//only works for stand-alone Jframe
    -->ComboBox2Thank you very much again for your answer
    BJoa

    Cast the event source object to what you added the listener to, here JComboBox
        JComboBox comboBox1 = new JComboBox();
        public void actionPerformed(ActionEvent e)
            JComboBox combo = (JComboBox)e.getSource();
            if(combo == comboBox1)
                doSomethingWith comboBox1();
            if(combo == comboBox2)
        }

  • Input value given on web page is not getting pickedup in event handler

    Hi friends,
    I have created one simple page in SE80 with program with flow logic option, in which I would like to show business partner details from BUT000 table with the input of partner number. But the thing is the input value(partner no.)which I am giving on web page is not getting picked up in selection in event handler though I am giving input value it is becoming initial while selecting. What could be the reason?
    Below I am mentioning the code which I have written in even handler for OnInputProcessing event.
    CASE EVENT_ID.
    WHEN 'select'.
    NAVIGATION->SET_PARAMETER( 'partner' ).
    SELECT * FROM but000 INTO TABLE I_but000 WHERE partner BETWEEN partner AND partner1.
    WHEN OTHERS.
    ENDCASE.
    Thanks in advance,
    Steve

    Hi Abhinav,
    I tried with the one you posted. But it is giving run time error as shown below.
    Note
    The following error text was processed in the system CRD : Access via 'NULL' object reference not possible.
    The error occurred on the application server crmdev_CRD_00 and in the work process 0 .
    The termination type was: RABAX_STATE
    The ABAP call stack was:
    Method: ONINPUTPROCESSING of program CLO24DDFJW575HVAQVJ89KWHEHC9OCP
    Method: %_ONINPUTPROCESSING of program CL_O24DDFJW575HVAQVJ89KWHEHC9OCP
    Method: DO_REQUEST of program CL_BSP_PAGE===================CP
    Method: ON_REQUEST of program CL_BSP_RUNTIME================CP
    Method: IF_HTTP_EXTENSION~HANDLE_REQUEST of program CL_HTTP_EXT_BSP===============CP
    Method: EXECUTE_REQUEST_FROM_MEMORY of program CL_HTTP_SERVER================CP
    Function: HTTP_DISPATCH_REQUEST of program SAPLHTTP_RUNTIME
    Module: %_HTTP_START of program SAPMHTTP
    Regards,
    Steve

  • Problem with event handling

    Hello all,
    I have a problem with event handling. I have two buttons in my GUI application with the same name.They are instance variables of two different objects of the same class and are put together in the one GUI.And their actionlisteners are registered with the same GUI. How can I differentiate between these two buttons?
    To be more eloborate here is a basic definition of my classes
    class SystemPanel{
             SystemPanel(FTP ftp){ app = ftp};
             FTP app;
             private JButton b = new JButton("ChgDir");
            b.addActionListener(app);
    class FTP extends JFrame implements ActionListener{
               SystemPanel rem = new SystemPanel(this);
               SystemPanel loc = new SystemPanel(this);
               FTP(){
                       add(rem);
                       add(loc);
                       pack();
                       show();
           void actionPerformed(ActionEvent evt){
            /*HOW WILL I BE ABLE TO KNOW WHICH BUTTON WAS PRESSED AS THEY
               BOTH HAVE SAME ID AND getSouce() ?
               In this case..it if was from rem or loc ?
    }  It would be really helpful if anyone could help me in this regard..
    Thanks
    Hari Vigensh

    Hi levi,
    Thankx..
    I solved the problem ..using same concept but in a different way..
    One thing i wanted to make clear is that the two buttons are in the SAME CLASS and i am forming 2 different objects of the SAME class and then putting them in a GUI.THERE IS NO b and C. there is just two instances of b which belong to the SAME CLASS..
    So the code
    private JButton b = new JButton("ChgDir");
    b.setActionCommand ("1");
    wont work as both the instances would have the label "ChgDir" and have setActionCommand set to 1!!!!
    Actually I have an array of buttons..So I solved the prob by writting a function caled setActionCmdRemote that would just set the action commands of one object of the class differently ..here is the code
    public void setActionCommandsRemote()
         for(int i = 0 ; i <cmdButtons.length ; i++)
         cmdButtons.setActionCommand((cmdButtons[i].getText())+"Rem");
    This just adds "rem" to the existing Actioncommand and i check it as folows in my actionperformed method
         if(button.getActionCommand().equals("DeleteRem") )          
                        deleteFileRemote();
          else if(button.getActionCommand().equals("Delete") )
                     deleteFileLocal();Anyway thanx a milion for your help..this was my first posting and I was glad to get a prompt reply!!!

  • OIm11g event handler-Bulk Orchestration

    Hi All,
    Can anyone help me with a sample code of bulk orchestration.
    Can i just copy and paste my execute() code in bulkexecute?
    My requirement is that my event handler shd work for a single user event
    Thanks
    -Mukul

    In case of updating a user from the console directly, in the Event Handlers one can implement the method
    public EventResult execute(long l1, long l2, Orchestration orchestration)This will get the CURRENT_USER_STATE and NEW_USER_STATE. For example, the user old attributes and the new changed attributes from the Orchestration class as :
    hm = orchestration.getInterEventData();
    oracle.iam.identity.usermgmt.vo.User oldUsr = (oracle.iam.identity.usermgmt.vo.User) hm.get(CURRENT_USER);
    oracle.iam.identity.usermgmt.vo.User newUsr = (oracle.iam.identity.usermgmt.vo.User) hm.get(NEW_USER_STATE);But in case of reconciliation from the database,one may want to implement the method
    public BulkEventResult execute(long arg0, long arg1, BulkOrchestration bulkOrchestration)There's a difference between single event and bulk event orchestration. In single event orchestration the interEventData gets populated with CURRENT_USER and NEW_USER_STATE, where each is an object storing the User's properties. But, bulk orchestration does not concern a single user. It's concern is multiple users in one event.
    CURRENT_USER and NEW_USER_STATE are still there, but they are not a single User object. They are actually an array of Identity objects (Identity is a superclass of User).

Maybe you are looking for

  • Need a new hard drive for my White Macbook (2008)

    my hard drive crashed and now it runs on the start up disk, i use to have 120 gb available now its down to 3 GB... and i get hard drive errors sometimes, and my macbook takes ages to load up (15 minutes), so i never restart it anymore, I need a link

  • Trouble with lcd hdtv

    I bought a lcd hdtv 2 years ago and just recently it goes to an all green screen perodically as we are watching it. What is that????

  • TS1398 since the new update (6.1) i am not able to connect to my wifi anymore.

    i need help since i downloaded the new updte (6.1) i hvae been experiencing not being able to connect to my wifi, my sister that has not updated yet has perfect connection. please help

  • [SOLVED] Problems with setting default printer in Libreoffice

    Everytime I print in Libreoffice it complains about me not having set the default printer. Where do I do that in Libreoffice or is it refferring to my setup in cups? Also in systemsettings under KDE4 when I try to manage my printer and I try to set i

  • Cannot Edit source definition of a report

    Hi All, I am new to Apex... I created a Master/Detail form. it automatically creates a report. I am trying to edit the report to add extra conditions but I go to the report page > Regions Zone > Select my report link > Source. It has an option to "Sh