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

ⅰ亾dé卋堺 提交于 2019-12-12 18:01:24

问题


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?


回答1:


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.




回答2:


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;
  }
}



回答3:


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



来源:https://stackoverflow.com/questions/3192440/how-can-i-set-the-insets-of-a-tooltip-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!