I need to implement nativeswing webbrowser component (chrriis.dj.nativeswing.swtimpl.components.JWebBrowser) in my application where I’m already using the docking frames project. As I notice, when using JWebBrowser with docking frames prevent me from navigating inside the webbrowser using the mouse click (Unable to navigate inside the webbrowser!!)
And As I noticed, just creating a new DockFrontend dockFrontend = new DockFrontend();
will cause the problem
Any help please?
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import bibliothek.gui.DockFrontend;
import chrriis.common.UIUtils;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
public class SimpleWebBrowserExample extends JFrame {
public SimpleWebBrowserExample() {
// Constructs the dock frontend.
DockFrontend dockFrontend = new DockFrontend();
setLayout(new net.miginfocom.swing.MigLayout("fill"));
setResizable(true);
JPanel webBrowserPanel = new JPanel(new net.miginfocom.swing.MigLayout("fill"));
final JWebBrowser webBrowser = new JWebBrowser(JWebBrowser.destroyOnFinalization());
webBrowser.navigate("www.google.com");
webBrowserPanel.add(webBrowser, "grow");
add(webBrowserPanel, "grow");
setSize(800, 600);
setLocationByPlatform(true);
doLayout();
setVisible(true);
webBrowserPanel.revalidate();
}
/* Standard main method to try that test as a standalone application. */
public static void main(String[] args) {
UIUtils.setPreferredLookAndFeel();
NativeInterface.open();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new SimpleWebBrowserExample();
}
});
NativeInterface.runEventPump();
}
}
I’ll try it during the weekend. DF uses some glass-panes (invisible panels lying over the user interface, catching and forwarding all MouseEvents), could be that the browser gets confused because of them.
Sorry for the long delay. My initiual guess was wrong and I still don’t exactly know what is happening, but at least how to repair it.
Normally my framework adds an AWTListener to the EventQueue to examine all MouseEvents and transfer focus between Dockables. In this case this mechanism seems to conflict with the browser.
Fortunatelly DockingFrames provides a “secure” modus, originally intended for applets, where no AWTListeners are used (they are a security risk for applets and thus not allowed). Activating this secure modus also allows to use the browser.
That is the code that worked for me:
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import bibliothek.gui.DockController;
import bibliothek.gui.DockFrontend;
import bibliothek.gui.dock.DefaultDockable;
import bibliothek.gui.dock.SplitDockStation;
import bibliothek.gui.dock.security.SecureDockControllerFactory;
import chrriis.common.UIUtils;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
public class WebBrowser extends JFrame {
public WebBrowser() {
// Constructs the dock frontend.
DockController controller = new DockController( new SecureDockControllerFactory() );
DockFrontend dockFrontend = new DockFrontend( controller, this );
setLayout( new BorderLayout() );
setResizable(true);
JPanel webBrowserPanel = new JPanel(new net.miginfocom.swing.MigLayout("fill"));
final JWebBrowser webBrowser = new JWebBrowser(JWebBrowser.destroyOnFinalization());
webBrowser.navigate("www.google.com");
webBrowserPanel.add(webBrowser, "grow");
SplitDockStation station = new SplitDockStation();
add( station );
dockFrontend.addRoot( "root", station );
DefaultDockable dockable = new DefaultDockable( webBrowser, "Browser" );
dockFrontend.addDockable( "browser", dockable );
station.drop( dockable );
setSize(800, 600);
setLocationByPlatform(true);
doLayout();
setVisible(true);
webBrowserPanel.revalidate();
}
/* Standard main method to try that test as a standalone application. */
public static void main(String[] args) {
UIUtils.setPreferredLookAndFeel();
NativeInterface.open();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new WebBrowser();
}
});
NativeInterface.runEventPump();
}
}```