Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am trying to write a program that shows images of a Java application's GUI automatically (ie, without someone building, running, and then taking screenshots of the interface).

I know WindowBuilder is a GUI designer with a WYSIWYG editor but that isn't quite what I want. For example, if given the source code (or jar) of an application as input, which has 4 frames (windows), then my tool would output 4 images of the different frames. It only needs to work on primitive and simple interfaces.

Any ideas on how to go about this?

EDIT: I would like to build this into an Eclipse plug-in that provides information to the developer about the GUI. There are plenty of plug-ins for showing the call graph in various ways, it would be neat to show a graph of the frames.

share|improve this question
    
Just to be clear, at runtime or at design time? For run-time, there are various related posts on the SO site; this one looked promising: stackoverflow.com/questions/2962271/… –  JustinC Jun 5 '13 at 3:05
    
@JustinC "behind the scenes" "without someone building, running, ..." So any method that I can use that follows that. –  Austin Henley Jun 5 '13 at 3:39
3  
So you want to take your source code and render its interface exactly as it will be when compiled and run... but without compiling and running it? Why? That is precisely the task of the compiler and virtual machine! Unless you think you can do a better job than the javac and JVM implementers, it's unlikely that this can work. –  Kilian Foth Jun 5 '13 at 6:37
1  
More information about the reason you want to do this might help us solve the underlying problem. –  dan1111 Jun 5 '13 at 8:11
1  
You might find good information in the question and answer here: stackoverflow.com/questions/2908418/… –  Alex Feinman Jun 5 '13 at 17:57

1 Answer 1

I try to sketch an approach (as I would do it):

  1. Find all sub-types of JFrame using Reflections.
  2. Instantiate a sub-type using Java Reflection API (java.lang.Class.newInstance()). This only possible if there's a no-argument constructor. Otherwise, do some magic argument guessing.
  3. Render this JFrame instance using the steps described in the link posted by Alex Feinman in the comments.

Of course, there many tricky things, e.g. dependencies to classes outside the package.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.