在BrowserView上无法看到JLabel工具提示

时间:2018-01-17 07:31:43

标签: java browser hidden jtooltip

我有这个问题:标签的工具提示(JLabel)被BrowserView隐藏。 工具提示正确显示在任何其他java组件的顶部,但被BrowserView隐藏。我想要的是使工具提示在BrowserView上显示。任何人都知道它的原因以及获得工具提示的方法。

结果用户界面以及隐藏工具提示的方式在此处附上。

代码示例:

public class TestFrame
{
  public static void main (String args[])
  {

    JSplitPane splitPane = new JSplitPane();

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    JPanel topPanel =  new JPanel();
    topPanel.setBorder(new LineBorder(Color.black));
    topPanel.setSize(75, 75);
    JLabel label = new JLabel("TestLabel");
    label.setToolTipText("Test Tooltip 1");
    topPanel.add(label);
    splitPane.setLeftComponent(topPanel);

    Browser browser = new Browser();
    BrowserView browserView = new BrowserView(browser);
    splitPane.setRightComponent(browserView);
    browser.loadURL("http://www.google.com");

    frame.add(splitPane);
    frame.setSize(700, 500);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
}

结果UI:右侧面板是一个BrowserView,它隐藏左面板标签的工具提示

enter image description here

2 个答案:

答案 0 :(得分:0)

让大家都知道,原因是JXBrowser是1.6.17,默认情况下它是重量级的。 而Jtooltip则是LightWeight。因为Jtooltip并没有出现在重量级浏览器之上。

几种解决方案。 1.使浏览器轻量级(com.teamdev.jxbrowser.chromium.BrowserType #LIGHTWEIGHT) 2.使Tooltip HeavyWeight

答案 1 :(得分:0)

您可以覆盖getToolTipLocation()并在特定位置(定义x和y坐标)设置工具提示文本:

class BrowserLabel extends JLabel {

    public BrowserLabel(String text) {
        setText(text);
    }

    @Override
    public Point getToolTipLocation(MouseEvent e) {
        return new Point(x, y);
    }
}