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

NullPointerException with ToolTipText

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.6
    • client-libs



      Name: el35337 Date: 06/18/98


      This JavaBean used to work fine with JDK-1.1.5 and swing-1.0.1.
      Now I use JDK-1.1.6 and swing-1.0.2 and I get the following message
      when I try to get the TipText with the mouse:

      Exception occurred during event dispatching:
      java.lang.NullPointerException
              at
      com.sun.java.swing.ToolTipManager$JPanelPopup.show(ToolTipManager.java:449)
              at
      com.sun.java.swing.ToolTipManager.showTipWindow(ToolTipManager.java:169)
              at
      com.sun.java.swing.ToolTipManager.mouseEntered(ToolTipManager.java:243)
              at
      java.awt.AWTEventMulticaster.mouseEntered(AWTEventMulticaster.java:246)
              at java.awt.Component.processMouseEvent(Component.java:2293)
              at java.awt.Component.processEvent(Component.java:2129)
              at java.awt.Container.processEvent(Container.java:894)
              at java.awt.Component.dispatchEventImpl(Component.java:1764)
              at java.awt.Container.dispatchEventImpl(Container.java:939)
              at java.awt.Component.dispatchEvent(Component.java:1704)
              at
      java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:1548)
              at java.awt.LightweightDispatcher.setMouseTarget(Container.java:1515)
              at
      java.awt.LightweightDispatcher.processMouseEvent(Container.java:1479)
              at java.awt.LightweightDispatcher.dispatchEvent(Container.java:1392)
              at java.awt.Container.dispatchEventImpl(Container.java:926)
              at java.awt.Component.dispatchEvent(Component.java:1704)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java:63)

      -------------
      The commands:

      javac Options.java
      jar -cvf Options.jar Meta-inf/Manifest.mf Options.class
      Options\$InnerAbstractAction.class

      ------------
      The content of the manifest file:

      Name: Options.class
      Java-Bean: True

      Name: Options$InnerAbstractAction.class
      Java-Bean: False

      ------------

      /**
       *
       * Options.java
       *
       */

      import java.awt.*;
      import java.awt.event.*;
      import java.util.*;
      import java.beans.*;
      //import java.awt.swing.*;
      //import java.awt.swing.event.*;
      import com.sun.java.swing.*;
      import com.sun.java.swing.event.*;

      public class Options extends JPanel {

        private Insets insets = new Insets(5,5,5,5);
        protected PropertyChangeSupport changes = new PropertyChangeSupport(this);
        protected EventListenerList changeListeners = new EventListenerList();
        private ButtonGroup rbg = new ButtonGroup();
        private String currentSelection = new String("");
        
        

        /**
         * The default constructor
         */
        public Options() {

          JRadioButton radioButton;

          // Give it a border so it stands out
          // By default, panels have no border
          setInsets(5,5,5,5);
          setBorder (BorderFactory.createEtchedBorder());
        
          // Set the layout of the panel to a BorderLayout
          //setLayout(new BorderLayout());
          setLayout(new GridLayout(4,1));

          // Create a label for the group
          JLabel label = new JLabel("Available schemes ");
          add(label);

          // Add a new radio button to the pane
          radioButton = new JRadioButton("Option 1");
          radioButton.setActionCommand("Option 1");
          radioButton.setMnemonic ('a');
          radioButton.setToolTipText("Some tip text for option 1...");
          add (radioButton);
          rbg.add (radioButton);
          radioButton.addActionListener(new InnerAbstractAction());
        
          // Set up more radio buttons
          radioButton = new JRadioButton("Option 2");
          radioButton.setActionCommand("Option 2");
          radioButton.setMnemonic ('b');
          radioButton.setToolTipText("Some tip text for option 2...");
          add (radioButton);
          rbg.add (radioButton);
          radioButton.addActionListener(new InnerAbstractAction());

          radioButton = new JRadioButton("Option 3");
          radioButton.setActionCommand("Option 3");
          radioButton.setMnemonic ('c');
          radioButton.setToolTipText("Some tip text for option 3...");
          add (radioButton);
          rbg.add (radioButton);
          radioButton.addActionListener(new InnerAbstractAction());
          // Set this radio button to be the default
          radioButton.setSelected(true);
          currentSelection = "Option 3";

        
          // Adjust to preferred size
          sizeToFit();
        }
        

        /*
         * Apply preferred size
         */
        private void sizeToFit() {
          Dimension d = new Dimension(getPreferredSize());
          setSize(d);
          doLayout();
          Component p = getParent();
            if (p != null) {
              p.invalidate();
              p.doLayout();
            }
        }

        /**
         * Get the insets
         */
        public synchronized Insets getInsets()
        { return insets; }
        
        /**
         * Set the insets
         */
        public synchronized void setInsets(int n1, int n2, int n3, int n4) {
          this.insets = new Insets(n1,n2,n3,n4);
        }

        /**
         * Get the current selection
         */
        public String getSelection() {
          String checkboxLabel = rbg.getSelection().getActionCommand();
          return checkboxLabel;
        }

        /**
         * Set the current selection
         */
        public void setSelection(String ac) {

          String oldSelection = currentSelection;
          currentSelection = ac;
          changes.firePropertyChange("selection", new String(oldSelection), new
      String(currentSelection));
          updateSelection(ac);
          fireChange();
        }

        /*
         * Update the selection from an action command string
         */
        private void updateSelection(String ac) {

          Enumeration e = rbg.getElements();
          AbstractButton ab;
          while(e.hasMoreElements())
            {
            ab = (AbstractButton)e.nextElement();
            if(ab.getActionCommand().equals(ac))
              {
              String oldSelection = currentSelection;
              currentSelection = ac;
              ab.setSelected(true);
              }
            else
              {
              ab.setSelected(false);
              }
            }
        }

        /**
         * This is used in the context of the MVC
         * design pattern
         *
         * Listener notification support
         */
        public void addChangeListener(ChangeListener x) {
          changeListeners.add (ChangeListener.class, x);

          // bring it up to date with current state
          x.stateChanged(new ChangeEvent(this));
        }

        public void removeChangeListener(ChangeListener x) {
          changeListeners.remove (ChangeListener.class, x);
        }

        protected void fireChange() {
          // Create the event:
          ChangeEvent c = new ChangeEvent(this);
          // Get the listener list
          Object[] listeners = changeListeners.getListenerList();
          // Process the listeners last to first
          // List is in pairs, Class and instance
          for (int i = listeners.length-2; i >= 0; i -= 2) {
            if (listeners[i] == ChangeListener.class) {
              ChangeListener cl = (ChangeListener)listeners[i+1];
              cl.stateChanged(c);
            }
          }
        }

        /**
         * The specified PropertyChangeListeners <b>propertyChange</b> method will
         * be called each time the value of any bound property is changed.
         * The PropertyListener object is addded to a list of
      PropertyChangeListeners
         * managed by this button, it can be removed with
      removePropertyChangeListener.
         * Note: the JavaBeans specification does not require
      PropertyChangeListeners
         * to run in any particular order.
         *
         * @see #removePropertyChangeListener
         * @param l the PropertyChangeListener
         */
          public void addPropertyChangeListener(PropertyChangeListener l) {
       changes.addPropertyChangeListener(l);
          }

        /**
         * Remove this PropertyChangeListener from the buttons internal list.
         * If the PropertyChangeListener isn't on the list, silently do nothing.
         *
         * @see #addPropertyChangeListener
         * @param l the PropertyChangeListener
         */
          public void removePropertyChangeListener(PropertyChangeListener l) {
       changes.removePropertyChangeListener(l);
          }
        

        /**
         * Inner class to support Abstract Actions for every schemes
         */
        public class InnerAbstractAction implements ActionListener {
          public InnerAbstractAction()
            {}
          public boolean isEnabled() { return true; }
          public void actionPerformed(ActionEvent e)
            {
            setSelection(rbg.getSelection().getActionCommand());
            }
        }
        

      }
      (Review ID: 32699)
      ======================================================================

            rschiavisunw Richard Schiavi (Inactive)
            elarsen Erik Larsen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: