first bug, if JCheckBox is the source of a ActionEvent and we call a e.getSource(), the output isnt the same than with the official sun VM. bugfix: change in javax.swing.JCheckBox the fonction paramString() to the following one: protected String paramString() { return super.paramString(); } second bug: if JCheckBox is the source of a ActionEvent and we call a e.getActionCommand(), we dont get the name of the button. bugfix: add setActionCommand(text); to the init() fonction of the JCheckbox. It willlokk like this: private void init() { setActionCommand(text); borderPainted = false; contentAreaFilled = false; } Third bug. If a button has no text and we get its actionCommand, we get null. But the sun vm gives us "". So i have two fixes, i dont know which one is more correct, probably the second one has less risks to disturb other things. bugfix(version1): add this "if" in the init fonction of javax.swing.AbstractButton: if(text == null) text = ""; This will set the text displayed in the button to "" if there is no text set. bugfix(version2): an alternative is to add this "if" to the fonction setActionCommand(String aCommand) of javax.swing.AbstractButton if(aCommand == null) aCommand = "";
Here is a test app I used to find out JDK's behavior (it is underspecified) :( public class Test { public static void main(String[] args) throws Exception { test(new JButton("bla")); test(new JRadioButton("bla")); test(new JToggleButton("bla")); test(new JCheckBox("bla")); } public static void test(AbstractButton jb) { System.out.println("class: " + jb.getClass()); // use the label by default System.out.println(jb.getActionCommand()); jb.setText("foo"); // changes when the label changes System.out.println(jb.getActionCommand()); jb.setText(null); // return null if the label is null System.out.println(jb.getActionCommand()); jb.setActionCommand("baz"); // as soon as the ac is set to a valid value return it System.out.println(jb.getActionCommand()); jb.setText("bla"); // and stay independent of the label changes System.out.println(jb.getActionCommand()); jb.setText(null); // really System.out.println(jb.getActionCommand()); jb.setActionCommand(null); jb.setText("bla"); // revert to default behavior when ac is unset System.out.println(jb.getActionCommand()); } }
The JDK simply reverts to using the button's label if the action command string is null. I fixed this in CVS.
First problem is solved with the fix to bug #13695. Second and third are fixed with my "actioncommand fixes" patch. Mauve tests are written. I close this one.