This discussion is archived
2 Replies Latest reply: Oct 14, 2011 7:14 AM by shakir.gusaroff RSS

Displaying Open Office word doc in browser using JavaFX

894508 Newbie
Currently Being Moderated
My requirement is to display open office doc in my application for modification
  • 1. Re: Displaying Open Office word doc in browser using JavaFX
    805536 Journeyer
    Currently Being Moderated
    A Google search reveals this library for writing the files: http://odftoolkit.org/projects/odfdom/pages/Home

    But I very much doubt there is anything out there to render it in JavaFX, so you will have to write the UI on your own.
  • 2. Re: Displaying Open Office word doc in browser using JavaFX
    shakir.gusaroff Expert
    Currently Being Moderated
    Hi. The following works for Microsoft Word docs and Notepad.
    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.stage.Stage;
    
    /**
     *
     * @author gusaros
     */
    public class OpenOffice extends Application {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            Application.launch(args);
        }
    
        @Override
        public void start(Stage primaryStage) {
            primaryStage.setTitle("Hello World");
            Group root = new Group();
            Scene scene = new Scene(root, 300, 250);
            Button btn = new Button();
            btn.setLayoutX(100);
            btn.setLayoutY(80);
            btn.setText("Hello World");
            btn.setOnAction(new EventHandler<ActionEvent>() {
    
                public void handle(ActionEvent event) {
                    String[] cmdArray = {"cmd", "/c", "start", "c:\\fdres.doc"};
    
                    try {
                        java.lang.Runtime.getRuntime().exec(cmdArray);
                    } catch (Exception s) {
                    }
    
    
                }
            });
            root.getChildren().add(btn);
            primaryStage.setScene(scene);
            primaryStage.show();
        }
    }

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points