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

The following examples show how to use javax.swing.JComponent#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 check out the related API usage on the sidebar.
Example 1
/**
 * 
 * @param event
 */
private void initiateToolTip(MouseEvent event) {

  JComponent component = (JComponent) event.getSource();
  String newToolTipText = component.getToolTipText(event);
  newToolTipComponent = ((ComponentToolTipProvider) component).getCustomToolTipComponent(event);

  if (newToolTipComponent == null)
    return;

  component.removeMouseMotionListener(moveBeforeEnterListener);

  Point location = event.getPoint();
  // ensure tooltip shows only in proper place
  if (location.x < 0 || location.x >= component.getWidth() || location.y < 0
      || location.y >= component.getHeight()) {
    return;
  }

  component.removeMouseMotionListener(this);
  component.addMouseMotionListener(this);

  mouseEvent = event;
  toolTipText = newToolTipText;
  preferredLocation = component.getToolTipLocation(event);
  insideComponent = component;

  showTipWindow();
}
 
Example 2
/**
 * Checks to see if the tooltip needs to be changed in response to the MouseMoved event
 * <code>event</code>.
 */
private void checkForTipChange(MouseEvent event) {
  JComponent component = (JComponent) event.getSource();
  String newText = component.getToolTipText(event);
  Point newPreferredLocation = component.getToolTipLocation(event);

  if (newText == null) {
    reset();
    hideTipWindow();
    return;
  }
  if (newPreferredLocation == null)
    return;

  if ((newText.equals(toolTipText))) {
    return;
  }

  newToolTipComponent = ((ComponentToolTipProvider) component).getCustomToolTipComponent(event);

  if (newToolTipComponent == null)
    return;

  toolTipText = newText;
  mouseEvent = event;
  preferredLocation = newPreferredLocation;
  hideTipWindow();
  showTipWindow();

}
 
Example 3
Source Project: netbeans   File: RendererPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String getToolTipText(MouseEvent event) {
    Component c = SwingUtilities.getDeepestComponentAt(this, event.getX(), event.getY());
    if (c instanceof JComponent) {
        JComponent jc = (JComponent) c;
        String tooltip = jc.getToolTipText();
        if (null != tooltip) {
            return tooltip;
        }
    }
    return super.getToolTipText(event);
}
 
Example 4
Source Project: netbeans   File: ListRendererPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String getToolTipText(MouseEvent event) {
    Component c = SwingUtilities.getDeepestComponentAt(this, event.getX(), event.getY());
    if (c instanceof JComponent) {
        JComponent jc = (JComponent) c;
        String tooltip = jc.getToolTipText();
        if (null != tooltip) {
            return tooltip;
        }
    }
    return super.getToolTipText(event);
}
 
Example 5
Source Project: netbeans   File: SummaryCellRenderer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean mouseMoved (Point p, JComponent component) {
    if (bounds != null && component.getToolTipText() == null) {
        for (Rectangle b : bounds) {
            if (b.contains(p)) {
                component.setToolTipText(text);
                return true;
            }
        }
    }
    return false;
}
 
Example 6
/**
 * 
 * @param event
 */
private void initiateToolTip(MouseEvent event) {

  JComponent component = (JComponent) event.getSource();
  String newToolTipText = component.getToolTipText(event);
  newToolTipComponent = ((ComponentToolTipProvider) component).getCustomToolTipComponent(event);

  if (newToolTipComponent == null)
    return;

  component.removeMouseMotionListener(moveBeforeEnterListener);

  Point location = event.getPoint();
  // ensure tooltip shows only in proper place
  if (location.x < 0 || location.x >= component.getWidth() || location.y < 0
      || location.y >= component.getHeight()) {
    return;
  }

  component.removeMouseMotionListener(this);
  component.addMouseMotionListener(this);

  mouseEvent = event;
  toolTipText = newToolTipText;
  preferredLocation = component.getToolTipLocation(event);
  insideComponent = component;

  showTipWindow();
}
 
Example 7
/**
 * Checks to see if the tooltip needs to be changed in response to the MouseMoved event
 * <code>event</code>.
 */
private void checkForTipChange(MouseEvent event) {
  JComponent component = (JComponent) event.getSource();
  String newText = component.getToolTipText(event);
  Point newPreferredLocation = component.getToolTipLocation(event);

  if (newText == null) {
    reset();
    hideTipWindow();
    return;
  }
  if (newPreferredLocation == null)
    return;

  if ((newText.equals(toolTipText))) {
    return;
  }

  newToolTipComponent = ((ComponentToolTipProvider) component).getCustomToolTipComponent(event);

  if (newToolTipComponent == null)
    return;

  toolTipText = newText;
  mouseEvent = event;
  preferredLocation = newPreferredLocation;
  hideTipWindow();
  showTipWindow();

}
 
Example 8
Source Project: jts   File: GuiUtil.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Changes the tooltip text of the JComponent to be multiline HTML.
 */
public static void formatTooltip(JComponent jcomponent) {
    String tip = jcomponent.getToolTipText();
    if (tip == null || tip.length() == 0)
        return;
    if (tip.toLowerCase().indexOf("<html>") > -1)
        return;
    tip = StringUtil.wrap(tip, 50);
    tip = StringUtil.replaceAll(tip, "\n", "<p>");
    tip = "<html>" + tip + "</html>";
    jcomponent.setToolTipText(tip);
}