java.awt.headless=true相关资料

之前一篇文章讲述linux如何转发jconsole的图形结果,其中涉及到 java.awt.headless=true,这次有朋友遇到这个问题,问题也查了半天未帮助其解决,为了更加详细的了解这个参数,故找了一些资料。

 

1:官方JDK中对于headless的支持说明

 

http://docs.oracle.com/javase/1.4.2/docs/guide/awt/AWTChanges.html#headless

 

重点在于:

 

Many of the methods in Toolkit and GraphicsEnvironment, with the exception of fonts, imaging, and printing, are changed to throw HeadlessException if a display, keyboard, and mouse are not supported


Applet, Button, Checkbox, Choice, FileDialog, Label, List, Menu, MenuBar, MenuComponent, MenuItem, PopupMenu, Scrollbar, ScrollPane, TextArea, TextComponent, Frame, Window, Dialog, JApplet, JFrame, JWindow, JDialog, and TextField. Canvas and Panel do not need to throw this exception since these can be given empty peers and treated as lightweights.

 

 

2:官方提供的使用headless模型的例子

 

 

Using Headless Mode in the Java SE Platform

 

http://java.sun.com/developer/technicalArticles/J2SE/Desktop/headless/

 

其中有以下例子 Canvas, Panel,  Image components

Methods related to Canvas, Panel, and Image components do not need to throw a HeadlessException because these components can be given empty peers and treated as lightweight components.

 

 

3:如何设置headless

 

Setting java.awt.headless=true programmatically

 

http://stackoverflow.com/questions/2552371/setting-java-awt-headless-true-programmatically

 

这里提供了3种方法

 

1:System.setProperty("java.awt.headless", "true");

2:-Djava.awt.headless=true

3:通过反射设置java.awt.GraphicsEnvironment中这个属性的值为true

 

 

4:headless模式下处理图片的一个实例

 

 

 java.awt.HeadlessException after setting java.awt.headless=true

 

http://www.theserverside.com/discussions/thread.tss?thread_id=52535

 

重点在于

 

 

对于headless支持不好的JFrame 使用FilteredImageSource 来处理。

 

FilteredImageSource myFilteredImageSource = new FilteredImageSource(image.getSource(), new CropImageFilter(x, y, crpHeight, crpWidth));

 

image = Toolkit.getDefaultToolkit().createImage(myFilteredImageSource); 

 

具体这个用法我不是很清楚,因为没接触过,不过如果有同学遇到,可以借鉴下。

你可能感兴趣的:(java)