Bug 23031 - Swing: 2 JCheckBox and 1 AbstractButton bugs, fixes included
Summary: Swing: 2 JCheckBox and 1 AbstractButton bugs, fixes included
Status: RESOLVED FIXED
Alias: None
Product: classpath
Classification: Unclassified
Component: classpath (show other bugs)
Version: unspecified
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-08 14:11 UTC by from-classpath
Modified: 2005-07-23 22:54 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description from-classpath 2005-07-08 14:11:50 UTC
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 = "";
Comment 1 from-classpath 2005-07-13 01:06:55 UTC
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());
	}
}
Comment 2 from-classpath 2005-07-13 01:20:38 UTC
The JDK simply reverts to using the button's label if the action command string is null. I fixed this in CVS.
Comment 3 from-classpath 2005-07-13 02:09:15 UTC
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.