When you embed BrowserView component into Java Swing frame with menu bar, by default you can see that browser component overlays pop-up menu as shown on the following screenshot:
(当您通过菜单栏将BrowserView组件嵌入Java Swing框架时,默认情况下,您会看到弹出菜单被浏览器组件遮挡,如下图所示:)
The reason of this issue is in mixing lightweight pop-up menu and heavyweight Browser component (by default Browser component is always heavyweight). To fix this issue you need to disable lightweight implementation of pop-ups using the following command: (此问题的原因是混合了轻量级弹出菜单和重量级浏览器组件(默认情况下,浏览器组件始终是重量级的)。要解决此问题,您需要使用以下命令来禁用轻量级弹出窗口的实现:)
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
This code forces all Swing pop-up menus to be heavyweight. As result you don't see the issue:
(此代码强制所有Swing弹出菜单都是重量级的。不会出现该问题:)
Source code of the example: (示例的源代码:)
import com.teamdev.jxbrowser.chromium.Browser; import com.teamdev.jxbrowser.chromium.swing.BrowserView; import javax.swing.*; import java.awt.*; public class BrowserSample { public static void main(String[] args) { JPopupMenu.setDefaultLightWeightPopupEnabled(false); Browser browser = new Browser(); BrowserView view = new BrowserView(browser); JMenu fileMenu = new JMenu("File"); fileMenu.add(new JMenuItem("Open...")); fileMenu.add(new JMenuItem("Close")); JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); JFrame frame = new JFrame(); frame.setJMenuBar(menuBar); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(new JTextField("http://www.google.com"), BorderLayout.NORTH); frame.add(view, BorderLayout.CENTER); frame.setSize(425, 290); frame.setLocationRelativeTo(null); frame.setVisible(true); browser.loadURL("http://google.com"); } }