Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4284401

bad doc for JToolBar.createActionComponent(Action)

    Details

    • Subcomponent:
    • Resolved In Build:
      kestrel
    • CPU:
      sparc
    • OS:
      solaris_2.6

      Description



      Name: sdC67446 Date: 10/25/99


       The doc for method
           protected JButton createActionComponent(Action a)
       of class
           javax.swing.JToolBar

      should say that the default name (getText()) is empty if null action
      is passed.

      The doc says:
      --------------------------------------------------
      protected JButton createActionComponent(Action a)

            Factory method which creates the JButton for Actions added to
            the JToolBar.
            Parameters:
                  a - the Action for the button to be added
            See Also:
                  Action

      The demo test:
      --------------------------------------------------
      import javax.swing.*;
      import java.awt.event.*;
      import java.beans.PropertyChangeListener;

      public class Test {

          public static class FakeJToolBar extends JToolBar {
              public JButton createActionComponent(Action a) {
                  return super.createActionComponent(a);
              }
          }

          public static class FakeAction implements Action {
              
              private String name;
              private Icon icon;
              private String short_description;
              private boolean isEnabled;
              
              public FakeAction(String name,
                                Icon icon,
                                String short_description,
                                boolean isEnabled) {
                  this.name = name;
                  this.icon = icon;
                  this.short_description = short_description;
                  this.isEnabled = isEnabled;
              }
              
              public Object getValue(String key) {
                  if (key.equals(Action.NAME)) {
                      return name;
                  } else if (key.equals(Action.SMALL_ICON)) {
                      return icon;
                  } else if (key.equals(Action.SHORT_DESCRIPTION)) {
                      return short_description;
                  } else {
                      return null;
                  }
              }
              public void putValue(String key, Object value) {}
              public void setEnabled(boolean b) {isEnabled = b;}
              public boolean isEnabled() {return isEnabled;}
              public void addPropertyChangeListener(PropertyChangeListener listener) {}
              public void removePropertyChangeListener(PropertyChangeListener listener) {}
              public void actionPerformed(ActionEvent e) {}
          }

          public static void main(String argv[]) {
              Icon icon = new ImageIcon();
              String short_description = "short_description";
              boolean isEnabled = true;

              FakeAction action = null;
              JButton button = null;
              String name = null;
              FakeJToolBar jtb = new FakeJToolBar();

              name = "test";
              action = new FakeAction(name, icon, "", false);
              button = jtb.createActionComponent(action);
              System.out.println(""+name+" -> \""+button.getText()+"\".");

              name = "";
              action = new FakeAction(name, icon, "", false);
              button = jtb.createActionComponent(action);
              System.out.println(""+name+" -> \""+button.getText()+"\".");

              name = null;
              action = new FakeAction(name, icon, "", false);
              button = jtb.createActionComponent(action);
              System.out.println(""+name+" -> \""+button.getText()+"\".");
          }
      }

      Output:
      --------------------------------------------------
      test -> "test".
       -> "".
      null -> "".
      ------------------------------------------------------------
      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              sharonz Sharon Zakhour (Inactive)
              Reporter:
              dsvsunw Dsv Dsv (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: