Skip to content

Instantly share code, notes, and snippets.

@ctrueden
Created February 26, 2018 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctrueden/29355778db5343b08266dba8d456a790 to your computer and use it in GitHub Desktop.
Save ctrueden/29355778db5343b08266dba8d456a790 to your computer and use it in GitHub Desktop.
import java.awt.Component;
import java.awt.Window;
import javax.swing.SwingUtilities;
import net.imagej.ImageJ;
import org.scijava.command.Command;
import org.scijava.plugin.Parameter;
import org.scijava.ui.UIService;
import org.scijava.ui.console.ConsolePane;
/**
* An illustration of how to access the SciJava Console window.
* <p>
* Assumes a Swing UI is active on the classpath.
* </p>
*/
public class ConsoleManipulator implements Command {
@Parameter
private UIService uiService;
@Override
public void run() {
final ConsolePane<?> consolePane = uiService.getDefaultUI().getConsolePane();
final Object component = consolePane.getComponent();
if (component instanceof Component) {
final Window window = SwingUtilities.getWindowAncestor((Component) component);
window.setBounds(300, 300, 500, 300);
}
}
public static void main(final String... args) throws Exception {
// Launch ImageJ as usual.
final ImageJ ij = new ImageJ();
ij.launch();
// Show the user interface.
ij.ui().showUI();
// Write some stuff to the console.
System.out.println("It's the output stream!");
System.err.println("It's the error stream!");
// Launch the command.
ij.command().run(ConsoleManipulator.class, true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment