Java Code Examples for javax.swing.JLabel#getToolTipText()

The following examples show how to use javax.swing.JLabel#getToolTipText() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@Override
public void mouseEntered(MouseEvent e) {
  dismissDelay = toolTipManager.getDismissDelay();
  initialDelay = toolTipManager.getInitialDelay();
  reshowDelay = toolTipManager.getReshowDelay();
  enabled = toolTipManager.isEnabled();
  Component component = e.getComponent();
  if(feature != null && !isTooltipSet && component instanceof JLabel) {
    isTooltipSet = true;
    JLabel label = (JLabel)component;
    String toolTip = label.getToolTipText();
    toolTip =
            (toolTip == null || toolTip.equals("")) ? "" : toolTip
                    .replaceAll("</?html>", "") + "<br>";
    toolTip = "<html>" + toolTip + "Right click to get statistics.</html>";
    label.setToolTipText(toolTip);
  }
  // make the tooltip indefinitely shown when the mouse is over
  toolTipManager.setDismissDelay(Integer.MAX_VALUE);
  toolTipManager.setInitialDelay(0);
  toolTipManager.setReshowDelay(0);
  toolTipManager.setEnabled(true);
}
 
Example 2
private void addStatistics(String kind, int count, int numRow,
        final MouseEvent e) {
  JLabel label = (JLabel)e.getComponent();
  if(!label.getToolTipText().contains(kind)) {
    // add the statistics to the tooltip
    String toolTip = label.getToolTipText();
    toolTip = toolTip.replaceAll("</?html>", "");
    toolTip = kind + " = " + count + "<br>" + toolTip;
    toolTip = "<html>" + toolTip + "</html>";
    label.setToolTipText(toolTip);
  }
  if(bottomSplitPane.getDividerLocation()
          / bottomSplitPane.getSize().getWidth() < 0.90) {
    // select the row in the statistics table
    statisticsTabbedPane.setSelectedIndex(1);
    oneRowStatisticsTable.setRowSelectionInterval(numRow, numRow);
    oneRowStatisticsTable.scrollRectToVisible(oneRowStatisticsTable
            .getCellRect(numRow, 0, true));
  } else {
    // display a tooltip
    JToolTip tip = label.createToolTip();
    tip.setTipText(kind + " = " + count);
    PopupFactory popupFactory = PopupFactory.getSharedInstance();
    final Popup tipWindow =
            popupFactory.getPopup(label, tip, e.getX()
                    + e.getComponent().getLocationOnScreen().x, e.getY()
                    + e.getComponent().getLocationOnScreen().y);
    tipWindow.show();
    Date timeToRun = new Date(System.currentTimeMillis() + 2000);
    Timer timer = new Timer("Annic statistics hide tooltip timer", true);
    timer.schedule(new TimerTask() {
      @Override
      public void run() {
        // hide the tooltip after 2 seconds
        tipWindow.hide();
      }
    }, timeToRun);
  }
}
 
Example 3
private void addStatistics(String kind, int count, int numRow,
        final MouseEvent e) {
  JLabel label = (JLabel)e.getComponent();
  if(!label.getToolTipText().contains(kind)) {
    // add the statistics to the tooltip
    String toolTip = label.getToolTipText();
    toolTip = toolTip.replaceAll("</?html>", "");
    toolTip = kind + " = " + count + "<br>" + toolTip;
    toolTip = "<html>" + toolTip + "</html>";
    label.setToolTipText(toolTip);
  }
  if(bottomSplitPane.getDividerLocation()
          / bottomSplitPane.getSize().getWidth() < 0.90) {
    // select the row in the statistics table
    statisticsTabbedPane.setSelectedIndex(1);
    oneRowStatisticsTable.setRowSelectionInterval(numRow, numRow);
    oneRowStatisticsTable.scrollRectToVisible(oneRowStatisticsTable
            .getCellRect(numRow, 0, true));
  } else {
    // display a tooltip
    JToolTip tip = label.createToolTip();
    tip.setTipText(kind + " = " + count);
    PopupFactory popupFactory = PopupFactory.getSharedInstance();
    final Popup tipWindow =
            popupFactory.getPopup(label, tip, e.getX()
                    + e.getComponent().getLocationOnScreen().x, e.getY()
                    + e.getComponent().getLocationOnScreen().y);
    tipWindow.show();
    Date timeToRun = new Date(System.currentTimeMillis() + 2000);
    Timer timer = new Timer("Annic statistics hide tooltip timer", true);
    timer.schedule(new TimerTask() {
      @Override
      public void run() {
        // hide the tooltip after 2 seconds
        tipWindow.hide();
      }
    }, timeToRun);
  }
}
 
Example 4
public boolean updateMode() {
   EntryMode newMode = getUser().getCurrentEntryMode();
   boolean changed = newMode != null && !newMode.equals(oldMode);
   for (EntryMode mode : EntryMode.values()) {
      if (modeMap.containsKey(mode)) {
         String text = getTextFor(mode);
         JLabel label = modeMap.get(mode);
         if (!text.equals(label.getText())) {
            label.setText(text);
            changed = true;
         }
         String modeTooltipKey = "tooltip." + mode.getI18nKey();
         String modeTooltipText = getString(modeTooltipKey);
         String oldTooltipText = label.getToolTipText();
         if (modeTooltipKey.equals(modeTooltipText)) {
            label.setToolTipText(null);
         } else if (!modeTooltipText.equals(oldTooltipText)) {
            label.setToolTipText(modeTooltipText);
         }
      }
   }
   String newModeLabel = getString(KEY_MODE_TEXT);
   if (!modeLabel.getText().equals(newModeLabel)) {
      changed = true;
      modeLabel.setText(newModeLabel);
   }
   if (changed) {
      JLabel oldSelection = modeMap.get(oldMode);
      JLabel newSelection = modeMap.get(newMode);
      setBorderFor(oldSelection, false);
      setBorderFor(newSelection, true);
      oldMode = newMode;
   }
   if (!modeMap.get(newMode).hasFocus()) {
      modeMap.get(newMode).requestFocusInWindow();
   }
   return changed;
}