How can I set the insets of a tooltip in Java?
Asked Answered
H

3

2

I created a Tooltip with a HTML formated text, this works fine, but I have no space between border and text. How can I set Insets or an EmptyBorder?

Harker answered 7/7, 2010 at 6:36 Comment(0)
G
3

Found this one article on how to change properties of Java ToolTip (background, border, etc.). It focuses on colors and border style but maybe you can use this approach for margins (insets) too.

Gaia answered 7/7, 2010 at 6:47 Comment(2)
thx ... it can be so easy ^^ UIManager.put( "ToolTip.border", BorderFactory.createCompoundBorder( UIManager.getBorder( "ToolTip.border" ), BorderFactory.createEmptyBorder( 10, 10, 10, 10 ) ) );Harker
Might not work with Nimbus LaF, because Nimbus does not read properties from UIManager. If you want to use Nimbus, use Nimbus.overrides client property to set Tooltip.border for Numbus, and UIManager for the rest - jasperpotts.com/blog/2008/08/skinning-a-slider-with-nimbusMclaurin
D
1

This works for me:

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JToolTip;
import javax.swing.border.EmptyBorder;

public class tooltipinsets {
  public static void main(String[] args) {
    JFrame window = new JFrame();
    JLabel lbl = new JLabel("Test") {
      @Override
      public JToolTip createToolTip() {
        return createCustomToolTip();
      }
    };
    window.add(lbl);
    lbl.setToolTipText("<html><b><i>This is the tooltip</i></b></html>");
    window.pack();
    window.setLocationRelativeTo(null);
    window.setVisible(true);
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }

  public static JToolTip createCustomToolTip() {
    JToolTip tip = new JToolTip();
    tip.setBorder(new EmptyBorder(10, 10, 10, 10));
    return tip;
  }
}
Dominicdominica answered 7/7, 2010 at 6:51 Comment(0)
D
0

I've read this article and think it's helpful for you. It suggests setting Margin from a Component and like-wise features...

Diastase answered 7/7, 2010 at 6:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.