From c2bea9c127d66e85aabe4d6cbd033f165496cdee Mon Sep 17 00:00:00 2001 From: weisj Date: Sat, 12 Oct 2019 00:36:32 +0200 Subject: [PATCH] Added demo for tooltip. --- src/test/java/ToolTipDemo.java | 47 ++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/test/java/ToolTipDemo.java diff --git a/src/test/java/ToolTipDemo.java b/src/test/java/ToolTipDemo.java new file mode 100644 index 00000000..1f543492 --- /dev/null +++ b/src/test/java/ToolTipDemo.java @@ -0,0 +1,47 @@ +import com.weis.darklaf.LafManager; +import com.weis.darklaf.components.tooltip.ToolTipContext; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseEvent; + +public class ToolTipDemo { + + public static void main(final String[] args) { + SwingUtilities.invokeLater(() -> { + LafManager.install(); + JFrame f = new JFrame(); + var p = new JPanel(); + p.add(new JButton("Button with very very long text") { + private final ToolTipContext context = new ToolTipContext(this); + + { + setToolTipText("ToolTip \n multiline \n third line's a charm"); + } + + @Override + protected void paintComponent(final Graphics g) { + super.paintComponent(g); + g.setColor(Color.RED); + g.fillRect(getWidth() / 2, getHeight() / 2, 1, 1); + } + + @Override + public JToolTip createToolTip() { + return context.getToolTip(); + } + + @Override + public Point getToolTipLocation(final MouseEvent event) { + return context.getToolTipLocation(event); + } + + + }); + f.setContentPane(p); + f.setLocationRelativeTo(null); + f.setSize(100, 100); + f.setVisible(true); + }); + } +}