NC65点击单据按钮打开web窗口
程序员文章站
2022-03-08 07:55:49
...
1.写一个Web窗口类
package nc.ui.plugin.view;
import java.awt.BorderLayout;
import javax.swing.SwingUtilities;
import nc.ui.pub.beans.UIPanel;
import chrriis.common.UIUtils;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
public class WebDialogPanel extends UIPanel {
private static final long serialVersionUID = 1530366704805472719L;
static {
NativeInterface.open();
UIUtils.setPreferredLookAndFeel();
}
private UIPanel mapPanel = null;
private JWebBrowser webBrowser = null;
private WebBrowserManager browserManager = null;
public WebDialogPanel() {
super();
}
public void initUI(String url) {
BorderLayout layout = new BorderLayout();
this.setLayout(layout);
UIPanel mapPanel = getMapPanel(url);
this.add(mapPanel, BorderLayout.CENTER);
}
private UIPanel getMapPanel(String url) {
if (mapPanel == null) {
mapPanel = new UIPanel();
BorderLayout layout = new BorderLayout();
mapPanel.setLayout(layout);
mapPanel.add(getWebBrowser(url), BorderLayout.CENTER);
}
return mapPanel;
}
private JWebBrowser getWebBrowser(String url) {
if (this.webBrowser == null) {
webBrowser = new JWebBrowser();
getBrowserManager(url).initBrowser(url);
}
return webBrowser;
}
private WebBrowserManager getBrowserManager(String url) {
if (this.browserManager == null) {
this.browserManager = new WebBrowserManager(getWebBrowser(url));
}
return browserManager;
}
private class WebBrowserManager {
private final JWebBrowser webBrowser;
public WebBrowserManager(JWebBrowser webBrowser) {
this.webBrowser = webBrowser;
}
public void initBrowser(final String url) {
webBrowser.setBarsVisible(false);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
webBrowser.navigate(url);
}
});
}
}
}
2.写一个NC的弹框
package nc.ui.plugin.view;
import java.awt.Dimension;
import java.awt.Toolkit;
import nc.ui.pub.beans.UIDialog;
@SuppressWarnings("restriction")
public class ClientUI extends UIDialog {
private static final long serialVersionUID = 1L;
public ClientUI() {}
public ClientUI(String url) {
initialize(url);
}
/**
* 初始化参数
* @param url
*/
public static void initdata(String url,String title) {
ClientUI dialog = new ClientUI(url);
// 设置标题
dialog.setTitle(title);
// 设置可以改变宽度
dialog.setReset(true);
// 设置dialog大小
Dimension ds = new Dimension(1000, 600);
dialog.setSize(ds);
// 获取屏幕大小
Dimension dsScreen = Toolkit.getDefaultToolkit().getScreenSize();
// 设置弹窗位置
dialog.setLocation((dsScreen.width - ds.width) / 2, (dsScreen.height - ds.height) / 2);
// 显示dialog
dialog.setVisible(true);
}
/**
* 初始化类。
*/
private void initialize(String url) {
nc.ui.plugin.view.WebDialogPanel imageWeb = new nc.ui.plugin.view.WebDialogPanel();
imageWeb.initUI(url);
getContentPane().add(imageWeb);
}
}
3.在自定义的按钮类doAction方法中直接调用
public void doAction(ActionEvent arg0) throws Exception {
ClientUI.initdata("https://www.baidu.com", "网页");
}
效果展示