文档



JavaFX:互操作性
L EnableButtons.java (发布 8)
L EnableButtons.java (发布 8)
package enablebuttons;
 
import javafx.application.Application;
import javafx.embed.swing.SwingNode;
import javafx.event.ActionEvent;
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.FlowPane;
import javafx.stage.Stage;
import javax.swing.SwingUtilities;
 
 
public class EnableButtons 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);
 
        FlowPane pane = new FlowPane();
        
        Image fxButtonIcon = new Image(getClass().getResourceAsStream("images/left.gif"));
 
        fxbutton = new Button("启用JButton", new ImageView(fxButtonIcon));
        fxbutton.setTooltip(new Tooltip("点击此按钮以启用Swing按钮。"));
        fxbutton.setStyle("-fx-font: 18 arial; -fx-base: #cce6ff;");
        fxbutton.setDisable(true);
       
        fxbutton.setOnAction((ActionEvent e) -> {
            SwingUtilities.invokeLater(() -> {
                ButtonHtml.b1.setEnabled(true);
            });
            fxbutton.setDisable(true);
        });
        
        pane.getChildren().addAll(swingNode, fxbutton);
   
        Scene scene = new Scene(pane, 300, 100);
        
        stage.setScene(scene);
        stage.setTitle("启用按钮示例");
        stage.show();
    }
    
    private void createSwingContent(final SwingNode swingNode) {
        SwingUtilities.invokeLater(() -> {
            swingNode.setContent(new ButtonHtml());
        });
    }        
}
关闭窗口

目录

JavaFX: 互操作性

展开 折叠

L EnableButtons.java (发布 8)