AWT Question

Discussions

Web tier: servlets, JSP, Web frameworks: AWT Question

  1. AWT Question (2 messages)

    Hi,
      I was trying to run the following code in UNIX:

    import java.awt.*;

    public class FontTest
    {
            public static void main(String[] args)
            {
                    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
                    Font[] fa = ge.getAllFonts();
                    for (int i=0; i<fa.length; i++)
                    {
                            System.out.println(fa[i].getFontName());
                    }
            }
    }


    But I got the following exception:
    Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the
    DISPLAY variable.
            at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
            at <Unloaded Method>
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Class.java:124)
            at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:63)
            at FontTest.main(Compiled Code)

    I am new to Java on UNIX. Please tell mw what is wrong with the system. Do I need to install something on this system?

    Thanks in advance

    Threaded Messages (2)

  2. AWT Question[ Go to top ]

    Hi,
    The error you are getting is because there is no XServer started on the unix machine. AWT tries to get the defaut fonts (colors, etc.) from the underlying windowing system, which in your case is not started. However if you want your test to work you should tell the JVM that is running in a non-window environment by setting the system property java.awt.headless=true.
    Best regards, Mircea
  3. Display variable[ Go to top ]

    The msg about DISPLAY variable points to something other than the previous user suggested. If that suggestion did not help, try this:


    If the program is on unix1 box and you did a telnet/ssh from win1 box,
    then you need to set the DISPLAY variable to your box. A best way to test this is to open a command window xterm etc after you set the display variable.

    set this

    setenv DISPLAY=win1.domain.com:0.0
    or
    export DISPLAY=win1.domain.com:0.0

    The same holds even if your box (win1) is a windows or unix.