javax.swing.JToolTip#setTipText ( )源码实例Demo

下面列出了javax.swing.JToolTip#setTipText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ghidra   文件: TruncatedTextListingHover.java
@Override
public JComponent getHoverComponent(Program program, ProgramLocation programLocation,
		FieldLocation fieldLocation, Field field) {

	if (!enabled || programLocation == null || !(field instanceof ListingTextField)) {
		return null;
	}

	if (((ListingTextField) field).isClipped()) {
		String text = field.getTextWithLineSeparators();
		String convertToHtml = HTMLUtilities.toLiteralHTMLForTooltip(text);
		JToolTip toolTip = new JToolTip();
		toolTip.setTipText(convertToHtml);
		return toolTip;
	}

	return null;
}
 
源代码2 项目: ghidra   文件: AbstractHover.java
protected JComponent createTooltipComponent(String content) {

		if (!isValidTooltipContent(content)) {
			return null;
		}

		JToolTip tt = new JToolTip();
		tt.setTipText(content);
		return tt;
	}
 
源代码3 项目: netbeans   文件: FlashingIcon.java
@Override
public Point getToolTipLocation( MouseEvent event ) {

    JToolTip tip = createToolTip();
    tip.setTipText( getToolTipText() );
    Dimension d = tip.getPreferredSize();
    
    
    Point retValue = new Point( getWidth()-d.width, -d.height );
    return retValue;
}
 
源代码4 项目: netbeans   文件: FlashingIcon.java
@Override
public Point getToolTipLocation(MouseEvent event) {

    JToolTip tip = createToolTip();
    tip.setTipText(getToolTipText());
    Dimension d = tip.getPreferredSize();


    Point retValue = new Point(getWidth() - d.width, -d.height);
    return retValue;
}
 
源代码5 项目: netbeans   文件: TableRendererTest.java
public void testTooltip() {
    setUpModel();
    JTable t = ot.treeTable.getTable();
    ot.revalidate();

    javax.swing.JFrame f = new javax.swing.JFrame();
    f.setLayout(new BorderLayout());
    f.add(ot, BorderLayout.CENTER);
    f.setSize(600, 500);
    f.setVisible(true);
    //while (f.isVisible()) {
        try {
            Thread.sleep(333);
        } catch (InterruptedException ex) {
            Exceptions.printStackTrace(ex);
        }
    //}

    MouseEvent event = getMouseClickAt(t, 0, 0);
    String tipText = t.getToolTipText(event);
    JToolTip tip = t.createToolTip();
    tip.setTipText(tipText);
    assertTrue("Bad ToolTip class: "+tip, tip instanceof RendererComponent.ToolTipComponent);
    assertEquals("ToolTip for Renderer of 0:DN", tip.getTipText());

    event = getMouseClickAt(t, 1, 1);
    tipText = t.getToolTipText(event);
    tip = t.createToolTip();
    tip.setTipText(tipText);
    assertFalse("Bad ToolTip class: "+tip, tip instanceof RendererComponent.ToolTipComponent);

    event = getMouseClickAt(t, 2, 2);
    tipText = t.getToolTipText(event);
    tip = t.createToolTip();
    tip.setTipText(tipText);
    assertTrue("Bad ToolTip class: "+tip, tip instanceof RendererComponent.ToolTipComponent);
    assertEquals("ToolTip for Renderer of 2:col2", tip.getTipText());
}
 
源代码6 项目: gate-core   文件: LuceneDataStoreSearchGUI.java
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);
  }
}
 
源代码7 项目: gate-core   文件: LuceneDataStoreSearchGUI.java
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);
  }
}
 
@Override
protected void query(CompletionResultSet completionResultSet, Document document, int caretOffset) {
    final StyledDocument styDoc = (StyledDocument) document;
    Element lineElement = styDoc.getParagraphElement(caretOffset);
    int lineStartOffset = lineElement.getStartOffset();
    int lineEndOffset = lineElement.getEndOffset();
    try {
        String line = styDoc.getText(lineStartOffset, lineEndOffset - lineStartOffset);
        if (line.endsWith("\n")) {
            line = line.substring(0, line.length() - 1);
        }
        if (showTooltip) {
            logger.log(FINER, "Tooltip on: {0}", line);
        } else {
            logger.log(FINER, "Documentation on: {0}", line);
        }
        if (!line.contains("#")) {
            //property name extraction from line
            Matcher matcher = PATTERN_PROP_NAME.matcher(line);
            if (matcher.matches()) {
                String propPrefix = matcher.group(1);
                ConfigurationMetadataProperty propMeta = sbs.getPropertyMetadata(propPrefix);
                if (propMeta != null) {
                    if (showTooltip) {
                        final JToolTip toolTip = new JToolTip();
                        toolTip.setTipText(Utils.shortenJavaType(propMeta.getType()));
                        completionResultSet.setToolTip(toolTip);
                    } else {
                        completionResultSet.setDocumentation(new CfgPropCompletionDocumentation(propMeta));
                    }
                }
            }
        }
    } catch (BadLocationException ex) {
        Exceptions.printStackTrace(ex);
    }
    completionResultSet.finish();
}
 
源代码9 项目: visualvm   文件: FlashingIcon.java
@Override
public Point getToolTipLocation( MouseEvent event ) {

    JToolTip tip = createToolTip();
    tip.setTipText( getToolTipText() );
    Dimension d = tip.getPreferredSize();
    
    
    Point retValue = new Point( getWidth()-d.width, -d.height );
    return retValue;
}
 
源代码10 项目: pumpernickel   文件: IOLocationTileList.java
@Override
public Point getToolTipLocation(MouseEvent event) {
	if (event != null) {
		Point p = event.getPoint();
		int index = locationToIndex(p);
		ListCellRenderer r = getCellRenderer();
		Rectangle cellBounds;

		if (index != -1 && (r instanceof BasicTileCellRenderer)
				&& (cellBounds = getCellBounds(index, index)) != null
				&& cellBounds.contains(p.x, p.y)) {
			String text = getToolTipText(event);
			JToolTip tip = new JToolTip();
			tip.setTipText(text);
			Dimension tipSize = tip.getPreferredSize();
			BasicTileCellRenderer btcr = (BasicTileCellRenderer) r;

			int yOffset = cellBounds.height / 2;
			if (btcr.thumbnail.getUI() instanceof ThumbnailLabelUI) {
				ThumbnailLabelUI ui = (ThumbnailLabelUI) btcr.thumbnail
						.getUI();
				yOffset = ui.getTextRect().y;
			}
			return new Point(cellBounds.x + cellBounds.width / 2
					- tipSize.width / 2, cellBounds.y + yOffset);
		}
	}
	return super.getToolTipLocation(event);
}
 
源代码11 项目: triplea   文件: MapUnitTooltipManager.java
@Override
public void actionPerformed(final ActionEvent e) {
  if (text != null && text.length() > 0) {
    final Point currentPoint = MouseInfo.getPointerInfo().getLocation();
    if (isPointWithinParentBounds(currentPoint)) {
      final PopupFactory popupFactory = PopupFactory.getSharedInstance();
      final JToolTip info = new JToolTip();
      info.setTipText("<html>" + text + "</html>");
      popup = popupFactory.getPopup(parent, info, currentPoint.x + 20, currentPoint.y - 20);
      popup.show();
    }
  }
}
 
private void showPopupAtMousePosition() {
	// StaticDebug.debug("DND POPUP: Show popup at Mouse position");
	// get mouse location
	Point screenLocation = MouseInfo.getPointerInfo().getLocation();
	screenLocation.x += 26;
	screenLocation.y += 10;

	// if tooltip is shown
	if (tipWindow != null) {
		// StaticDebug.debug("DND POPUP: Popup is already shown");

		// check if mouse has moved
		if (mouseX != screenLocation.x || mouseY != screenLocation.y) {
			// StaticDebug.debug("DND POPUP: old position x = "+mouseX);
			// StaticDebug.debug("DND POPUP: old position y = "+mouseY);
			// StaticDebug.debug("DND POPUP: new position x = "+screenLocation.x);
			// StaticDebug.debug("DND POPUP: new position y = "+screenLocation.y);
			// StaticDebug.debug("DND POPUP: Mouse position has changed.. hide popup first");
			// hide tooltip
			hideDropDeniedTooltip();
		} else {
			// StaticDebug.debug("DND POPUP: Restart hide timer to prevent popup from being hidden.");
			// otherwise restart hide timer
			hideTimer.restart();
			return;
		}
	}

	Point componentLocation = (Point) screenLocation.clone();
	SwingUtilities.convertPointFromScreen(componentLocation, popupSource);
	if (tipWindow == null && popupSource.contains(componentLocation)) {
		// StaticDebug.debug("DND POPUP: Mouse is inside popupSource and popup is not shown");
		JToolTip tip = popupSource.createToolTip();
		tip.setTipText(reason);
		PopupFactory popupFactory = PopupFactory.getSharedInstance();

		mouseX = screenLocation.x;
		mouseY = screenLocation.y;

		// StaticDebug.debug("DND POPUP: show popup at "+mouseX+","+mouseY+" and start hide timer");
		tipWindow = popupFactory.getPopup(popupSource, tip, mouseX, mouseY);
		tipWindow.show();
		hideTimer.restart();
	}
}