예제 #1
0
  private void removeLabel(Object key) {
    for (JLabel addedLabel : _labelComponents) {

      LabelItem labelItem = _itemDictionary.get(addedLabel);
      if (labelItem.getTag() == key) {

        _labelComponents.remove(addedLabel);
        remove(addedLabel);
        _itemDictionary.remove(addedLabel);
        break;
      }
    }
    revalidate();
    repaint();
  }
예제 #2
0
  private void addLabel(LabelItem label) {

    JLabel newLabel = new JLabel(label.getText());
    newLabel.setVisible(true);
    _labelComponents.add(newLabel);
    _itemDictionary.put(newLabel, label);

    newLabel.addMouseListener(
        new java.awt.event.MouseAdapter() {
          public void mouseClicked(java.awt.event.MouseEvent evt) {
            JLabel eventSender = (JLabel) evt.getComponent();

            LabelItem labelItem = _itemDictionary.get(eventSender);
            _controller.RemoveLabel(labelItem);
          }
        });
    add(newLabel);
    revalidate();
  }