I want to know, which way is the best way to open devtools.
Some requirements:
- JDialog
- 1 Method for opening(create)/put to foreground (if already open)
- 2 ways to open it. 1.) Open via MenuBar (w/o inspectAt) 2.) Open via context menu (with inspectAt)
So, I need only one method. If the window/dialog is closed it should be created and if it is open already (maybe in background) it should be put to foreground and inspectAt should be refreshed.
Maybe someone has a good working method for it
This is my method, but it is not really good and it makes some problems under windows:
- Code: Select all
private JDialog devToolsDialog;
private CefBrowser devTools;
- Code: Select all
public void openDevTools(Frame owner, CefBrowser cefBrowser, Point inspectAt)
{
if (devToolsDialog == null || !devToolsDialog.isValid())
{
devToolsDialog = new JDialog();
devToolsDialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
devToolsDialog.addWindowListener(new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent e)
{
if (devTools != null)
{
devTools.close();
devTools = null;
}
}
});
} else
{
devToolsDialog.removeAll();
}
devTools = cefBrowser.getDevTools(inspectAt);
devToolsDialog.add(devTools.getUIComponent());
devToolsDialog.setSize(800, 600);
devToolsDialog.validate();
devToolsDialog.setVisible(true);
}