wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Can't connect to X11 window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Can Watch "Can New topic
Author

Can't connect to X11 window

Kiran Baratam
Greenhorn

Joined: Sep 03, 2003
Posts: 27
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Kiran Baratam
Greenhorn

Joined: Sep 03, 2003
Posts: 27
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't connect to X11 window
 
Similar Threads
Inserting an Image in JTextField
Getting error when running swing program
Layout is leaving some pixels on the right
when running swing program getting error
rgdg awt on Linux {java.lang.InternalError}