I'm trying to listen to a change of selection in a Java JComboBox. I have tried to use an ActionListener but the problem is this: the action listener does something like this   public void actionPerformed(ActionEvent e){     JComboBox&lt;String&gt; source = ((JComboBox&lt;String&gt;)e.getSource());     String selected = source.getItemAt(source.getSelectedIndex());      /*now I compare if the selected string is equal to some others        and in a couple of cases I have to add elements to the combo*/ }   As you can notice, when I need to add elements to the combo another event is fired and the actionPerformed method is called again, even if I don't want that, and the code may loops... :( Is there any way to listen to the selection change only and not to a generic change event? Thanks
113588
I'm trying to get an event to fire whenever a choice is made from a JComboBox.  The problem I'm having is that there is no obvious addSelectionListener() method.  I've tried to use actionPerformed(), but it never fires.  Short of overriding the model for the JComboBox, I'm out of ideas.  How do I get notified of a selection change on a JComboBox?**  Edit: I have to apologize. It turns out I was using a misbehaving subclass of JComboBox, but I'll leave the question up since your answer is good.
12184
I'm trying to get an understanding of what the the java keyword this actually does. I've been reading Sun's documentation but I'm still fuzzy on what this actually does.
28108
If i do jQuery(expr).change( function), then I can get an event function to fire when the user makes a change to the value.  Is it possible to get this to fire if it's changed programatically, ie if I call jQuery(expr).val("moo").  or if some Plain old JavaScript changes it's value?  Thanks for any help.
19919
I ran into an interesting behavior recently.  It seems that if I override .equals() to take a parameter other than Object, it doesn't get called.  Can anyone explain to me why this is happening?  It seems to violate my understanding of polymorphism in OOP, but maybe I'm missing something.  Here's much simpler code that shows what I'm seeing:  public class MyClass {   private int x;   public MyClass(int n) { x = n; }   public boolean equals(Object o) { return false; }   public boolean equals(MyClass mc) { return x == mc.x; }   public static void main(String[] args) {     List&lt;MyClass&gt; list = new ArrayList&lt;MyClass&gt;();     list.add(new MyClass(3));     System.out.println("Contains 3? " + list.contains(new MyClass(3)));   } }   When this is run, it prints "Contains 3? false".  It looks like the equals(Object) function is called, even though there is another that would work.  By contrast, if I write equals like this the code works as expected:  public boolean equals(Object o) {   if(!(o instanceof MyClass))     return false;   MyClass mc = (MyClass)o;   return x == mc.x; }   Why isn't it figuring out which version of the function to call based on the type of the parameter?
40160
DataGridView.CellContentClick is not firing if I mouse click a DataGridViewCheckBoxCell very fast. How can I solve this? I need to know when CheckBox's check state changes
38330
I'm developing a LWC Combobox and I want to get the label of the selected value in the handleChange() method, not the id. I filled the combobox with JSON Items in this form :   {value :'Id', label:'Label'}   I used this in JS : event.detail.value but it gives the id not the Label.
41675
When interacting with different elements and applying multiple actions it  may be quite convenient in some situations if we could do:  WebElement myInput = driver.findElement(By.id("my-input-id")); myInput.clear().sendKeys("test");   Instead of:  WebElement myInput = driver.findElement(By.id("my-input-id")); myInput.clear() myInput.sendKeys("test");   But, the problem is , sendKeys() and other "action" methods cannot be chained as is - they return void and not the current WebElement.  What would be the easiest way to achieve chaining multiple actions?
44766
For example, is it possible to bind the label of a button to a "myButtonLabel" attribute by adding an expression string like in the following example?    $A.createComponent(         "ui:button",         {             "aura:id": "findableAuraId",         //EXAMPLE:             "label": "{!v.myButtonLabel}",         "press": cmp.getReference("c.handlePress")         },         function(newButton){             //Add the new button to the body array             if (cmp.isValid()) {                 var body = cmp.get("v.body");                 body.push(newButton);                 cmp.set("v.body", body);             }         }     );
51297
I moved a method that sets addError() from a trigger into a Helper class. As I started writing test code for it it seems like the addError() is not actually preventing DML operations for the records that get modified in the helper class.  The information from the SF  states: Marks a trigger record with a custom error message and prevents any DML operation from occurring.  Does this mean that addError() will not work outside of a trigger class?  EDIT  Adding some sample code.  public class MyHelperClass() {     public static void someMethod(Opportunity opp) {         opp.My_Field__c.addError('Some error');         insert opp;     } }   And sample test for it without any asserts:  @IsTest private class MyHelperClass_Test() {     @IsTest     static void someTest() {         Opportunity opp = new Opportunity();         opp.Name = 'Some Name';         opp.StageName = 'Prospect';         opp.CloseDate = Date.today().addDays(30);          MyHelperClass.someMethod(opp);     } }   The above inserts the opportunity and does not trigger an exception. Am I doing something wrong?
92972
I want to put individual JComboBoxes into each cells of a JTable. ie. The JComboBox content is not identical for each cell.   I basically would like to be able to just call the following code to add a row of JComboBox into the JTable. Anyone has any idea? Thanks  JComboBox cb1 = new JComboBox(...); JComboBox cb2 = new JComboBox(...); model.addRow(new Object[] {"Row name", cb1, cb2} );  JComboBox cb3 = new JComboBox(...); JComboBox cb4 = new JComboBox(...); model.addRow(new Object[] {"Row name 2", cb3, cb4} );   The closest example code I can find is as follows. But it is for where JComboBox content is identical for the individual column. Not the solution I need.  TableColumn col = table.getColumnModel().getColumn(vColIndex); col.setCellEditor(new MyComboBoxEditor(values));   where  public class MyComboBoxEditor extends DefaultCellEditor {     public MyComboBoxEditor(String[] items) {         super(new JComboBox(items));     } }
25403
private JButton jBtnDrawCircle = new JButton("Circle"); private JButton jBtnDrawSquare = new JButton("Square"); private JButton jBtnDrawTriangle = new JButton("Triangle"); private JButton jBtnSelection = new JButton("Selection");   How do I add action listeners to these buttons, so that from a main method I can call actionperformed on them, so when they are clicked I can call them in my program?
32609
Is there any way to automatically get notified of property changes in a class without having to write OnPropertyChanged in every setter?  (I have hundreds of properties that I want to know if they have changed).    Anton suggests .  I've actually used the "Castle" library for something similar in the past, and while it does reduce the amount of code I've had to write, it added around 30 seconds to my program startup time (ymmv) - because it's a runtime solution.  I'm wondering if there is a compile time solution, maybe using compile-time attributes...    Slashene and TcKs give suggestions which generates repetitive code - unfortunately, not all my properties are a simple case of m_Value = value - lots of them have custom code in the setters, so cookie-cutter code from snippets and xml aren't really feasible for my project either.
84342
I have a JFrame. This JFrame contains a JButton. I click the JButton and 10 JTextFields are created.  the problem: I cannot see them until "I force a repaint()" by resizing the window. Only then do I see the JTextFields created.  CODE:  JPanel points = new JPanel();  //Creating the JTextFields: for (int i=0; i&lt;10; i++) {     JTextField textField = new JTextField();     points.add(textField); }  repaint(); this.repaint(); super.repaint(); points.repaint();     THANK YOU - after the for loop, I just called points.validate() and it worked...
89069
In the javadoc it says that EventListener is      "A tagging interface that all event listener interfaces must extend."   Why is that? What's the significance of making a custom listener implement EventListner? Is there any special handling for EventListner somewhere?
8344
I'm working with a bit of html and Javascript code that I've taken over from someone else. The page reloads a table of data (via an asynchronous request) every ten seconds, and then re-builds the table using some DOM code. The code in question looks something like this:  var blah = xmlres.getElementsByTagName('blah'); for(var i = 0; i &lt; blah.length; i++) {     var td = document.createElement('td');     var select = document.createElement('select');     select.setAttribute("...", "...");     select.onchange = function() {         onStatusChanged(select, callid, anotherid);     };     td.appendChild(select); }   When the onchange event is fired for a &lt;select&gt; element however, it seems like the same values are being passed to the onStatusChanged() method for every &lt;select&gt; in the table (I've verified that in each iteration of the loop, callid and anotherid are being given new, distinct values).   I suspect this is occuring because of the nature of how I am setting the event handler, with the select.onchange = function() syntax. If I understand how this is working correctly, this syntax sets a closure for the onchange event to be a function which refers to these two references, which end up having a final value of whatever they are set to on the last iteration of the loop. When the event fires, the value referenced by callid and anotherid is the value set in the last iteration, not the value set at the individual iteration.  Is there a way that I can copy the value of the parameters I am passing to onStatusChanged()?  I've changed the title to better reflect the question and the accepted answer.
106441
I have a method like this:  public static &lt;T&gt; boolean isMemberOf(T item, T[] set) {     for (T t : set) {         if (t.equals(item)) {             return true;         }     }     return false; }   Now I try to call this method using a char for T:  char ch = 'a'; char[] chars = new char[] { 'a', 'b', 'c' }; boolean member = isMemberOf(ch, chars);   This doesn't work. I would expect the char and char[] to get autoboxed to Character and Character[], but that doesn't seem to happen.  Any insights?
90873
I have an Enumerable&lt;T&gt; and am looking for a method that allows me to execute an action for each element, kind of like Select but then for side-effects. Something like:  string[] Names = ...; Names.each(s =&gt; Console.Writeline(s));   or   Names.each(s =&gt; GenHTMLOutput(s));    // (where GenHTMLOutput cannot for some reason receive the enumerable itself as a parameter)   I did try Select(s=&gt; { Console.WriteLine(s); return s; }), but it wasn't printing anything.