K EnableFXButton.java
有关描述,请参见在JavaFX应用程序中嵌入Swing内容。
法律条款和版权声明
/* * 版权所有 (c) 2011, 2014, Oracle及其附属公司。 * 保留所有权利。使用受许可条款约束。 * * 此文件可在以下许可下使用和许可: * * 源代码的重新发布和使用,无论是否进行修改,只要满足以下条件: * * - 必须保留上述版权声明、此条件列表和以下免责声明。 * - 以二进制形式重新发布时,必须在文档和/或其他提供的材料中复制上述版权声明、此条件列表和以下免责声明。 * - 未经特定事先书面许可,不得使用Oracle或其贡献者的名称来认可或推广从本软件派生的产品。 * * 本软件由版权持有人和贡献者“按原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性和适用性的暗示保证。 * 在任何情况下,版权所有人或贡献者均不对任何直接、间接、偶然、特殊、惩罚性或后果性损害(包括但不限于替代商品或服务的采购、使用、数据或利润损失,或业务中断)承担任何责任,无论是合同责任、严格责任还是侵权行为(包括疏忽或其他)的理论,即使事先已被告知此类损害的可能性。 */
代码
package enablefxbutton; import javafx.application.Application; import javafx.embed.swing.SwingNode; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Tooltip; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.BorderPane; import javafx.stage.Stage; import javax.swing.SwingUtilities; public class EnableFXButton extends Application { public static Button fxbutton; public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) { final SwingNode swingNode = new SwingNode(); createSwingContent(swingNode); BorderPane pane = new BorderPane(); Image fxButtonIcon = new Image(getClass().getResourceAsStream("images/middle.gif")); fxbutton = new Button("FX按钮", new ImageView(fxButtonIcon)); fxbutton.setTooltip(new Tooltip("当您点击此中间按钮时,它不会执行任何操作。")); fxbutton.setStyle("-fx-font: 22 arial; -fx-base: #cce6ff;"); pane.setTop(swingNode); pane.setCenter(fxbutton); Scene scene = new Scene(pane, 300, 100); stage.setScene(scene); stage.setTitle("启用FX按钮"); stage.show(); } private void createSwingContent(final SwingNode swingNode) { SwingUtilities.invokeLater(() -> { swingNode.setContent(new ButtonHtml()); }); } }