2

HTML 形式のテキストでツールチップを作成しました。これは正常に機能しますが、境界線とテキストの間にスペースがありません。Insets または EmptyBorder を設定するにはどうすればよいですか?

4

3 に答える 3

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.

于 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 に答える