Skip to content

Constructs a tree of the components in a swing application

License

Notifications You must be signed in to change notification settings

CIRDLES/SwingTree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwingTree

Constructs a tree of the components in a swing application

Swing Tree by Discovery

You can add this repository to your Java Project using JitPack.

Example

import java.io.FileWriter;
import java.io.IOException
import com.github.luskjh.SwingTree;

/* We're using the automaton library (https://github.com/renatoathaydes/Automaton) 
 * for its GUI selectors
 */
import com.athaydes.automaton.Swinger;

...

/* Here we're using reflection to get the main class of the swing application */
Class<?> mainClass = Class.forName("package.then.classname");
Method method = mainClass.getDeclaredMethod("main", String[].class);
        
/* Start swing application */
String[] params = {};
method.invoke(null, (Object) params);

swinger = Swinger.forSwingWindow();

/* Give time for application to start */
swinger.pause(500);

Component frame = swinger.getAt("type:FrameClassName");

/* assemble tree */
SwingTree st = new SwingTree(frame);

/* Get JSON - currently the only output format supported */
JSONObject obj = st.toJSON();

/* Write to file */
try (FileWriter file = new FileWriter("/path/to/file.json")) {
    file.write(obj.toJSONString());
} catch (IOException e) {
    System.out.println("Error writing JSON to file");
}

About

Constructs a tree of the components in a swing application

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages