File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't connect to X11 window

 
Kiran Baratam
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
I have written a small swing program which is working perfectly in Windows.When i try to run the same program in unix its giving 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 sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:5
4)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:115)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvi
ronment.java:53)
at java.awt.Window.<init>(Window.java:183)
at java.awt.Frame.<init>(Frame.java:310)
at java.awt.Frame.<init>(Frame.java:289)
at javax.swing.JFrame.<init>(JFrame.java:167)
at LabelDemo.<init>(LabelDemo.java:9)
at LabelDemo.main(LabelDemo.java:45)
Can you please help me.
i am thinking some problem with look and feel but not sure.
Plase help me.
Here is my code
import java.awt.*;
import javax.swing.*;
class LabelDemo
extends JFrame
{
public LabelDemo()
{
super("JLabel Demo");
setSize(600, 100);
JPanel content = (JPanel) getContentPane();
content.setLayout(new GridLayout(1, 4, 4, 4));
JLabel label = new JLabel();
label.setText("JLabel");
label.setBackground(Color.white);
content.add(label);
label = new JLabel("JLabel",
SwingConstants.CENTER);
label.setOpaque(true);
label.setBackground(Color.white);
content.add(label);
label = new JLabel("JLabel");
label.setFont(new Font("Helvetica", Font.BOLD, 18));
label.setOpaque(true);
label.setBackground(Color.white);
content.add(label);
ImageIcon image = new ImageIcon("flight.gif");
label = new JLabel("JLabel", image,
SwingConstants.RIGHT);
label.setVerticalTextPosition(SwingConstants.TOP);
label.setOpaque(true);
label.setBackground(Color.white);
content.add(label);
setVisible(true);
}
public static void main(String args[])
{
new LabelDemo();
}
}
Regards
Kiran
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is just a common X11 application problem, not a Java thing, really. We can't help you debug it without knowing a bit more about your environment. It actually would be much easier for someone at your end who knew something about X to help you figure out what's going on.
One possibility: you've use "telnet" or similar to connect to a remote UNIX server from your Windows box, and are running the app on the server, but you don't have an X server on your desktop machine for it to display to.
 
Kiran Baratam
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:

One possibility: you've use "telnet" or similar to connect to a remote UNIX server from your Windows box, and are running the app on the server, but you don't have an X server on your desktop machine for it to display to.

Hi Ernest
Yes i am connecting to unix box through telnet and tryimng to execute.
my normal javaprogram is working fine like this only.
Kiran
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, then.
You need a program called an "X server" to run on your desktop machine. The way that X/Windows works is that a program (a Java program, or any graphical program) sends commands to the X server to tell it to display windows on its behalf. If you don't have an X server on your local machine, then the program will fail and won't be able to display a GUI.
There are commercial X servers for Windows like eXceed and Hummingbird, and there is at least one free one (the Cygwin port of XFree86, see http://cygwin.com/xfree/ .)
Alternatively, instead of getting an X server, you could use VNC; see http://www.tightvnc.com/ for one version of this open-source software.
Before you deccide that X/Windows sucks, think about how, from the UNIX machine, you would run the Windows version of your program (actually, VNC would let you do this, too.)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic