bug-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug classpath/23031] Swing: 2 JCheckBox and 1 AbstractButton bugs, fixe


From: gcc-bugzilla at gcc dot gnu dot org
Subject: [Bug classpath/23031] Swing: 2 JCheckBox and 1 AbstractButton bugs, fixes included
Date: 8 Sep 2010 18:04:53 -0000

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 from-classpath at savannah dot gnu dot org  2005-07-13 
01:06 -------
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 from-classpath at savannah dot gnu dot org  2005-07-13 
01:20 -------
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 from-classpath at savannah dot gnu dot org  2005-07-13 
02:09 -------
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.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23031




reply via email to

[Prev in Thread] Current Thread [Next in Thread]