【发布时间】:2010-07-07 06:36:07
【问题描述】:
我创建了一个带有 HTML 格式文本的工具提示,效果很好,但我在边框和文本之间没有空格。如何设置 Insets 或 EmptyBorder?
【问题讨论】:
我创建了一个带有 HTML 格式文本的工具提示,效果很好,但我在边框和文本之间没有空格。如何设置 Insets 或 EmptyBorder?
【问题讨论】:
找到这篇关于如何change properties of Java ToolTip (background, border, etc.) 的文章。它侧重于颜色和边框样式,但也许您也可以将这种方法用于边距(插图)。
【讨论】:
这对我有用:
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;
}
}
【讨论】:
我已阅读此article 并认为它对您有帮助。它建议从Component 和类似的功能设置保证金...
【讨论】: