示例#1
0
 /**
  * Removes the component at the specified index from this popup menu.
  *
  * @param pos the position of the item to be removed
  * @exception IllegalArgumentException if the value of <code>pos</code> < 0, or if the value of
  *     <code>pos</code> is greater than the number of items
  */
 public void remove(int pos) {
   if (pos < 0) {
     throw new IllegalArgumentException("index less than zero.");
   }
   if (pos > getComponentCount() - 1) {
     throw new IllegalArgumentException("index greater than the number of items.");
   }
   super.remove(pos);
 }
示例#2
0
  /**
   * Sets the content that the popup displays
   *
   * @param content A JComponent that represents the content to be displayed.
   */
  public void setContent(JComponent content) {
    if (content == null) {
      throw new NullPointerException("Popup content must not be null");
    }

    // Remove the previous popup content
    if (this.content != null) {
      glassPane.remove(this.content);
    }

    // Set this content to the new content
    this.content = content;

    // Set the size of the content
    this.content.setSize(this.content.getPreferredSize());

    // Put the content into the glass pane
    glassPane.add(this.content);
  }