【问题标题】:How can I set the insets of a tooltip in Java?如何在 Java 中设置工具提示的插图?
【发布时间】:2010-07-07 06:36:07
【问题描述】:

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

【问题讨论】:

    标签: java tooltip insets


    【解决方案1】:

    找到这篇关于如何change properties of Java ToolTip (background, border, etc.) 的文章。它侧重于颜色和边框样式,但也许您也可以将这种方法用于边距(插图)。

    【讨论】:

    • thx ... 原来如此简单 ^^ UIManager.put( "ToolTip.border", BorderFactory.createCompoundBorder( UIManager.getBorder( "ToolTip.border" ), BorderFactory.createEmptyBorder( 10, 10, 10, 10 ) ) );
    • 可能不适用于 Nimbus LaF,因为 Nimbus 不会从 UIManager 读取属性。如果你想使用 Nimbus,请使用 Nimbus.overrides 客户端属性为 Numbus 设置 Tooltip.border,其余部分使用 UIManager - jasperpotts.com/blog/2008/08/skinning-a-slider-with-nimbus
    【解决方案2】:

    这对我有用:

    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】:

      我已阅读此article 并认为它对您有帮助。它建议从Component 和类似的功能设置保证金...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-01-10
        • 1970-01-01
        • 2011-02-13
        • 2016-10-19
        • 1970-01-01
        • 1970-01-01
        • 2019-09-14
        相关资源
        最近更新 更多