views:

192

answers:

1

So, I've got a Swing GUI that, for testing purposes (the other applications that my task will interact with aren't all developed yet), I'd like to be able to give a "debug console" to.

The idea being that I could use this console to explicitly set values in my model, and verify that the appropriate GUI elements get updated. The Eclipse debugger's "display tab" is basically exactly what I want - once you hit a breakpoint, you can type in Java code that's applicable to the current method's context, and execute it as if that code was part of the source at the current breakpoint.

But, I want this as part of my application - without having to run a separate application (Eclipse), set a breakpoint, hit the breakpoint, etc. (That's what I'm doing now - it works, but it's slightly annoying.) Is there any existing library that includes something like that?

A: 

One interesting technique here is to use a text pane in conjunction with JavaScript (the Rhino engine is built into the JRE now). The script will have access to your application objects and vice-versa.

Here's info on calling Java from JavaScript

and here's info on executing the script from the Java side - the code examples there pretty much build of what you are wanting to do (just take the text in the textpane and execute it using the scripting engine).

We use this sort of thing for advanced configuration dialogs where we are introducing features but don't have a solid GUI built around them yet. It's cool b/c you can implement an interface in JavaScript, then use the resultant object elsewhere in the Java app.

Kevin Day
That's pretty nice, thanks! (Now I just need to go learn JavaScript...)
Sbodd
hah - it's not hard for what you are probably trying to do - set a variable, inspect a variable. I'll leave it up to you to decide if you should mark my response as the accepted answer :-)
Kevin Day
Yep, definitely sufficient for my needs at the moment - much appreciated.
Sbodd