How to prevent creation of multiple tool instances from different windows?
in
Library and Tool Development
•
2 years ago
I've been trying to create a processing tool. I want to have just one instance of the tool running, irrespective of how many sketch windows are open. If the tool has been launched from one sketch window, launching it again from another window should bring the previous instance back to focus. How do I achieve it? I tried declaring the JFrame as static, doesn't work. Here's the code:
Test1 is a class which extends JFrame and is the tool window.
- public class Test1Tool implements Tool {
- static Test1 t = null;
- public String getMenuTitle() {
- return "Test1 Tool";
- }
- public void init(Editor theEditor) {
- t = new Test1();
- t.editor = theEditor;
- }
- public void run() {
- t.setVisible(true);
- }
- }
1