windows 来自Java应用程序的Activex?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/239395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:31:51  来源:igfitidea点击:

Activex from java application?

javawindowsactivex

提问by Marko

Is it possible to easily embed ActiveX controls in Java application? Is it worth it. In my next project I should either use existing activex in Java app or have to reimplement everything from scratch, so I'm wondering what will be less hassle.

是否可以在 Java 应用程序中轻松嵌入 ActiveX 控件?这值得么。在我的下一个项目中,我应该要么在 Java 应用程序中使用现有的 activex,要么必须从头开始重新实现所有内容,所以我想知道什么会不那么麻烦。

回答by alexmcchessers

I don't think there's a way to do this without resorting to a third party library. (Or rolling your own, but you did say "easily".)

我认为不求助于第三方库就没有办法做到这一点。(或者滚动你自己的,但你确实说“容易”。)

SWT(The "Standard Widget Toolkit") contains support for embedding ActiveX controls. SWT is an alternative to Swing, though there is a degree of interoperability between them.
Here'san example of embedding Windows Media Player in an SWT window.

SWT(“Standard Widget Toolkit”)包含对嵌入 ActiveX 控件的支持。SWT 是 Swing 的替代品,尽管它们之间存在一定程度的互操作性。
下面是在 SWT 窗口中嵌入 Windows Media Player 的示例。

Alternatively there's the Jacobproject, though I haven't used that myself.

或者还有Jacob项目,尽管我自己没有使用过。

As for "is it worth it?" Well, I can say from experience that SWT makes it relatively easy, but unless your application can gracefully deal with not having them available, by relying on COM components you are losing the ability to run on multiple platforms that makes Java attractive in the first place.

至于“值得吗?” 好吧,我可以从经验中说,SWT 使它变得相对容易,但是除非您的应用程序能够优雅地处理它们不可用的情况,否则通过依赖 COM 组件,您将失去在多个平台上运行的能力,而这首先使 Java 具有吸引力.

回答by Kevin Day

It really depends on how much you are going to have to re-implement. The Jacob projectis quite good (we use it extensively for automation of Excel and Word), but you have to reallyunderstand COM to use it, especially the vagaries of the IDispatch interface (very few people who use ActiveX / COM actually understand COM - they just rely on Microsoft's template generation).

这实际上取决于您需要重新实施多少。该雅各项目是相当不错的(我们用它广泛用于Excel和Word自动化),但你要真正了解COM使用它,尤其是IDispatch接口(谁使用ActiveX / COM很少有人变幻莫测的真正理解COM -他们只是依赖微软的模板生成)。

If you are just trying to save yourself some typing for some simple DAO objects, you'll probably be better off re-implementing (heck, you could probably take the DTD and write a script to generate Java code for it).

如果您只是想为一些简单的 DAO 对象节省一些输入,那么重新实现可能会更好(见鬼,您可能会采用 DTD 并编写一个脚本来为其生成 Java 代码)。

回答by rogerdpack

http://www.codeproject.com/KB/cross-platform/javacom.aspx?msg=1776281might help if you're willing to do stuff by hand...

http://www.codeproject.com/KB/cross-platform/javacom.aspx?msg=1776281可能会有所帮助,如果你愿意手工做的东西......

Doesn't seem quite as flexible though...

不过好像不太灵活……