org.fxmisc.richtext.demo.TooltipDemo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of richtextfx Show documentation
Show all versions of richtextfx Show documentation
FX-Text-Area for formatted text and other special effects.
package org.fxmisc.richtext.demo;
import java.time.Duration;
import javafx.application.Application;
import javafx.geometry.Point2D;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Popup;
import javafx.stage.Stage;
import org.fxmisc.richtext.event.MouseOverTextEvent;
import org.fxmisc.richtext.StyleClassedTextArea;
/**
* Name: TooltipDemo
* Description: .
*
* Comment: ...
*
* Copyright: Copyright (c) 2016-2019
* Company: >StA-Soft<
* @author StA
* @version 1.0
*/
public class TooltipDemo extends Application
{
/**
* Main-Methode.
* @param args Kommandozeilenparameter
*/
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage stage)
{
StyleClassedTextArea area = new StyleClassedTextArea();
area.setWrapText(true);
area.appendText("Pause the mouse over the text for 1 second.");
Popup popup = new Popup();
Label popupMsg = new Label();
popupMsg.setStyle(
"-fx-background-color: black;" +
"-fx-text-fill: white;" +
"-fx-padding: 5;");
popup.getContent().add(popupMsg);
area.setMouseOverTextDelay(Duration.ofSeconds(1));
area.addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_BEGIN, e ->
{
int chIdx = e.getCharacterIndex();
Point2D pos = e.getScreenPosition();
popupMsg.setText("Character '" + area.getText(chIdx, chIdx + 1) + "' at " + pos);
popup.show(area, pos.getX(), pos.getY() + 10);
});
area.addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_END, e ->
{
popup.hide();
});
Scene scene = new Scene(area, 600, 400);
stage.setScene(scene);
stage.setTitle("Tooltip Demo");
stage.show();
}
}