2

我创建了一个带有 HTML 格式文本的工具提示,这很好用,但我在边框和文本之间没有空格。如何设置 Insets 或 EmptyBorder?

4

3 回答 3

3

找到这篇关于如何更改 Java ToolTip 属性(背景、边框等)的文章。它专注于颜色和边框样式,但也许您也可以将这种方法用于边距(插图)。

于 2010-07-07T06:47:35.623 回答
1

这对我有用:

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;
  }
}
于 2010-07-07T06:51:43.837 回答
0

我读过这篇文章,认为它对你有帮助。它建议从一个和类似的功能设置保证金......Component

于 2010-07-07T06:49:47.833 回答