Debian Codegraph @

freehep-graphicsbase/src/main/java/org/freehep/graphicsbase/swing/Headless.java

raw
1 package org.freehep.graphicsbase.swing;
2
3 import javax.swing.JComponent;
4 import javax.swing.JInternalFrame;
5
6 /**
7 * A class which aids in creating swing components in a "headless" environment.
8 * Useful for using swing components to export graphics to a file, without requiring
9 * a connection to a display (i.e. with -Djava.awt.headless=true).
10 * @author Tony Johnson
11 * @author Mark Donszelmann
12 */
13 @SuppressWarnings("serial")
14 public class Headless extends JInternalFrame {
15
16 public Headless(JComponent component) {
17 setContentPane(component);
18 }
19 // Note, this must override the (deprecated) method show, not setVisible
20 public void show() {
21 super.show();
22 // Although the above calculates the size of the components, it does not lay them out.
23 // For some reason frame.validate simply delegates to Container.validate(), which does nothing
24 // if there is no peer defined.
25 addNotify();
26 synchronized(super.getTreeLock()) {
27 super.validateTree();
28 }
29 }
30 }