【问题标题】:JLabel tooltip is not visible on top of BrowserViewJLabel 工具提示在 BrowserView 顶部不可见
【发布时间】:2018-01-17 07:31:42
【问题描述】:

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

此处附有生成的 UI 和工具提示的隐藏方式。

代码示例:

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,它隐藏了左侧面板标签的 Tooltip

【问题讨论】:

  • 尝试设置 label.setPreferedsize
  • 刚刚在原始问题中进行了调整,我希望工具提示在 BrowserView 顶部可见,即使标签很小。

标签: java browser hidden jtooltip


【解决方案1】:

让大家知道,这是因为 JXBrowser 是 1.6.17 并且默认情况下它是重量级的。 Jtooltip 是 LightWeight。因为 Jtooltip 不会出现在重量级浏览器的顶部。

很少有解决方案。 1. 使浏览器轻量级(com.teamdev.jxbrowser.chromium.BrowserType#LIGHTWEIGHT) 2. 让 Tooltip 变得更重

【讨论】:

    【解决方案2】:

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

    class BrowserLabel extends JLabel {
    
        public BrowserLabel(String text) {
            setText(text);
        }
    
        @Override
        public Point getToolTipLocation(MouseEvent e) {
            return new Point(x, y);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-10
      • 1970-01-01
      • 2018-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多