Run JFrame in gui less linux os - java

Recently I switch to linux with no desktop os.
I have installed java successfull but when i run program of JFrame then it throws exception like
java.awt.HeadlessException
java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
java.awt.Window.(Window.java:432)
java.awt.Frame.(Frame.java:403)
javax.swing.JFrame.(JFrame.java:202)
now I could not understand how can I fix this problem?
I want to run JFrame & even I dont want to remove os as well.
thanks in advance.

Well, if the OS doesn't have any desktop, only command line, where do you expect the window to be drawn? If the OS doesn't have desktop, then you can only use command line.
You can try Charva, as #BenjaminDale suggested, but that will offer only limited functionality.

Swing can only work with os supporting desktop (head / screen). In the case of headless os, I can't understand any use case of JFrame.
So you'll either have to get rid of JFrame from your program (which seems logical (there is no desktop)) or run it on an os with a head :)
Hope this helps.

The article Using Headless Mode in the Java SE Platform describes the limitations imposed on applications intended to run in headless mode. For applications that cannot be usefully converted, some alternatives are mentioned here, including xvfb and vnc.

Related

Java/Swing: Desktop.open() causes GTK-ERROR

I am currently developing a Swing Desktop application. This application is also using a tray icon which is handled by SystemTray of dorkbox.
Now I need to open a file with the default application. To achieve this I am using the Desktop.open() method of AWT like this.
if (Desktop.isDesktopSupported()) {
System.out.println("Get desktop.");
Desktop desktop = Desktop.getDesktop();
System.out.println("Got desktop.");
desktop.open(file);
}
But now here comes the problem: On some devices (which apparently have GTK2 and GTK3 installed this few lines make application crash - the program crashes while executing the Desktop.isDesktopSupported() line with a gtk-error ** gtk+ 2.x symbols detected. using gtk+ 2.x and gtk+ 3 is not supported.
To be honest, I have no clue, what is going wrong here - but if only GTK3 is installed the application runs like a charm. The SystemTray seems to be using GTK3 as well because I did not explicitly set it up to use GTK2.
So, what's causing this mix of GTK2 and 3? Is there a way to force the Desktop class to use the right version of GTK (the same, as being used by the rest of the application)?
It won't resolve your current problem but there is another way to open file with the default application.
On Windows:
Runtime.getRuntime().exec("C:\SomeFolder\Somefile.txt");
On Mac and Linux:
Runtime.getRuntime().exec("xdg-open /folder/file.txt");
Hope it will help you, if you won't resolve your current problem.

Mac OS X 10.10 (Yosemite) Java Swing Look and Feel?

When I launch a java application using Swing for the GUI, I notice on Mac that Swing still renders the "old" Mac UI (10.9 and older). Since Oracle is now responsible to write the JRE for Mac OS X - where can I find any new UI?
Or are there any alternatives out there?
This spiked my curiosity since it also bothers me.
#MadProgrammer appears to be correct. Acoording to the Oracle's page about Look and Feels, HP, IBM and Apple provide their own Look and Feels.
To my understanding, this clears Oracle's responsability over the out of date L&F, and transfers it to Apple itself.
The only foreseeable option is to wait for updates...

Java program works when browser is Safari but not Opera/Firefox/Chrome

I have a simple Java program that includes a robot which clicks things inside of a browser based on pixel location. It works on Safari, but not on Opera. Why is this? Is it because of the Java version I have? Is it because Opera is a 32-bit browser? Could somebody explain to me how to allow the Java program to run when my browser is Opera?
For reference:
http://help.opera.com/opera/Mac/1558/en/index.html
(See bottom where it discusses why Java may not be working.)
EDIT: I'm running a Mac OS X 64-bit machine.
EDIT: I even restored to Java SE 6.
EDIT: I even switched to Firefox, a 64-bit browser, but the java program still won't work. Any idea anybody?
Different browsers have different pixel colors for the same thing.

Java swing components not displayed properly outside netbeans

I have developed a Java Swing application. When running the application in Netbeans IDE, everything works properly (see http://www.fkserv.ugent.be/vrg/tom_dierickx/Screenshot2.png for a screenshot).
After building the project to .jar and running it in command line, the application window appears but the components are not displayed properly (See http://www.fkserv.ugent.be/vrg/tom_dierickx/Screenshot1.png for a screenshot).
Does anyone have experienced this before and may have a solution to this problem?
As the thread points out, this seems to be a Ubuntu-related problem. I experienced no trouble when running the application on a windows system.
Some threads on the web contribute the defect to Compiz or Beryl. However, I never installed these graphic-tools. However, I ran a line of code I found on the net for uninstalling Compiz. It seemed that Compiz was installed by default. Unfortunately, the problem remains. Beryl doesn't seem to be installed.
The threads also note to add export AWT_TOOLKIT="MToolkit", but this doesn't seem to work either.
No runtime errors where generated on the command line.
Any suggestions?
After some testing, I came to following conclusions:
The application runs on Windows, but not on Ubuntu.
Some Swing applications run on Ubuntu, while others don't.
Hence it seems like the problem is due to one or a few Swing components which do not work in Ubuntu. I think it's best for now to avoid these components by testing what works and what does not.

SWT Browser Problem on Vista

We're running Java Swing and are using an SWT bridge to get ahold of the SWT browser. Everything normally works just fine, but we have a problem on a Vista test machine. It worked fine until just a week ago or so. The call stack:
org.eclipse.swt.SWTError: No more handles
at org.eclipse.swt.SWT.error(SWT.java:3589)
at org.eclipse.swt.SWT.error(SWT.java:3481)
at org.eclipse.swt.SWT.error(SWT.java:3452)
at org.eclipse.swt.browser.IE.create(IE.java:184)
at org.eclipse.swt.browser.Browser.<init>(Browser.java:109)
...
I have tried IE7 and IE8 through the SWT browser, but none is working (XULRunner is not applicable on our application since we need two browser instances).
XP, Windows7 and Vista is working on other machines, and I can't exclude something being correpted on this specific machine. We got some Windows updates close to when this error started happening, they seem related. It is a our only Vista test machine with a virtual screen, has there been any Windows updates for IE relating to virtual screens that could cause this? To me it looks like a likely target for security holes, so maybe that could be it?
I know this is looking for a needle in a haystack, but has anybody seen anything similar lately?
Edit: looking at the source, I see that the IE.create method swallows an exception to throw this error - I'd step into the WebSite constructor to try and figure out what's happening.
My solution is not to embed the SWTBrowser into our Swing application at all. (I've always hated web tech on desktop apps anyway. :)

Categories

Resources