Editing Javascript and rendering HTML in one window I've been trying to learn the basics of Javascript, so this afternoon I put together a small JavaFX application that has a raw text area on the left, and an HTML rendering on the right:



public class Fifty extends Application {
    private String filePath = null;
    private TextArea text;
    public void init() throws Exception {
        super.init();
        Parameters parameters = getParameters();
        List&lt;String&gt; unnamedParams = parameters.getUnnamed();
        if (unnamedParams.size() &gt; 0) {
            filePath = unnamedParams.get(0);
        }
    }
    public void start(Stage stage) throws Exception {
        SplitPane splitPane = new SplitPane();
        text = new TextArea();
        final WebView web = new WebView();
        try {
            text.setText(readFile(filePath, Charset.defaultCharset()));
            web.getEngine().loadContent(text.getText());
        } catch (Exception e) {
            alertException(e);
        }
        text.setStyle("-fx-font-family: monospace");
        text.textProperty().addListener(new ChangeListener&lt;String&gt;() {
            @Override
            public void changed(final ObservableValue&lt;? extends String&gt; observable,
                    final String oldValue, final String newValue) {
                web.getEngine().loadContent(text.getText());
            }
        });
        splitPane.getItems().addAll(text, web);
        Scene scene = new Scene(splitPane);
        scene.setFill(Color.RED);
        stage.setScene(scene);
        stage.setTitle("eleven-fifty: because i'm bad at naming things");
        stage.show();
    }
    public void stop() {
        try {
            saveFile(filePath, text.getText());
        } catch (Exception ex) {
            ex.printStackTrace();
            System.err.println("file not saved!");
        }
    }
    static String readFile(String path, Charset encoding) throws IOException {
        byte[] encoded = Files.readAllBytes(Paths.get(path));
        return new String(encoded, encoding);
    }
    static void saveFile(String path, String text) throws Exception {
        PrintWriter out = new PrintWriter(path);
        out.print(text);
        out.close();
    }
    static void alert(String title, String body) {
        Alert alert = new Alert(AlertType.INFORMATION);
    alert.setTitle(title);
    alert.setContentText(body);
    alert.show();
    }
    static void alertException(Exception e) {
        StackTraceElement[] trace = e.getStackTrace();
        int i = 0;
        StringBuilder traceRes = new StringBuilder();
        traceRes.append(String.format("%s\n", e.toString()));
        for (StackTraceElement element: trace) {
            traceRes.append(String.format("%s\n", element.toString()));
            if (++i &gt; 10) break;
        }
        alert("Exception", traceRes.toString());
    }
}


Finally, a script to automatically launch the .jar file:

java -jar eleven-fifty.jar %1
pause


How can this simple application be improved?
Style review


Added newlines between methods – Your code looks mighty cramped, and this makes it harder to read, which in turn makes it harder to understand. This also applies to places within code. When programming in Python the guidelines says to use two new lines between methods, and if needed one new line in code. That is good advice
Keep good indentation and consistent brace style – It looks like you mostly have good indentation, and consistent brace styles. I like that (mostly) you're using braces around even one line blocks. That's good!

There are a little slip up in the alert() method, and similar a hidden break in the alertException()
Add comments – You should have some comments in the code indicating what the different parts do, and when they do it. Not what the code does, but why it does is that way


Code suggestions


To me it is not clear when you execute the new code, of if it is continously being executed. I would not continuosly execute it, and rather have some buttons to start and stop execution. 
I would also have a (scrolling) panel for the javascript console output, if possible. Lots of messages will be made to the console, and otherwise be hidden
In due time you'll also need to have the ability to have the possibility to edit the html section, so maybe you need to have a button or panel to allow editing that as well
In other words, I think I would divide the left panel into javascript and raw html, whilst the right panel is divided into the html output and javascript console. And some buttons or menu somewhere. If possible in JavaFX the divider in either panel should be movable to accomodate for whatever part is the longer, and of course they should have scrollbar if text extends the panel