Can Java webstart dialog caption be overridden? - java

I have an Angular web application as well as a client JavaFX program that I host on an IIS 7 web server. When user clicks on a link on a page in the web app, I construct the proper JNLP file and send it down to the browser. The client browser then opens the JNLP file and the app loads and then opens properly. No issues.
But the webstart dialog that appears after clicking on the link shows a progress bar as it downloads the java application from the server, and it's got a caption that says 'JavaFX Application Preview'. I'd much rather have it say the name of the software the user is downloading. Is this possible? If so, where should I start looking?
I hunted online and couldn't find a single mention of this, which I find really surprising. Surely this has come up before?

Create a custom Preloader and in the start method of the preloader, set the title of the preloader stage.

Related

Java: Can't connect to X11 window server using 'localhost:1.0' as the value of the DISPLAY variable

I have created a web application which makes use of JOptionPane to display some dialogs to the users such as 'Record not found etc'. I did this development in Windows and everything was working fine.
I was then asked to deploy the project war on a remote server which is a RHEL machine without any GUI (similar to AWS machines). When i run my we application over there i get the below mentioned exception wherever there is a JOptionPane statement.
Exception in thread "http-bio-8080-exec-6" java.lang.InternalError: Can't connect to X11 window server using 'localhost:1.0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:62)
at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:178)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.X11GraphicsEnvironment.(X11GraphicsEnvironment.java:142)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:188)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
at sun.swing.SwingUtilities2.isLocalDisplay(SwingUtilities2.java:1393)
at javax.swing.plaf.metal.MetalLookAndFeel.initComponentDefaults(MetalLookAndFeel.java:1563)
at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults(BasicLookAndFeel.java:147)
at javax.swing.plaf.metal.MetalLookAndFeel.getDefaults(MetalLookAndFeel.java:1599)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:530)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:570)
at javax.swing.UIManager.initializeDefaultLAF(UIManager.java:1320)
at javax.swing.UIManager.initialize(UIManager.java:1407)
at javax.swing.UIManager.maybeInitialize(UIManager.java:1395)
at javax.swing.UIManager.getDefaults(UIManager.java:644)
at javax.swing.UIManager.getString(UIManager.java:790)
at javax.swing.UIManager.getString(UIManager.java:807)
at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:610)
I have already tried to use export DISPLAY also tried
System.setProperty("java.awt.headless", "true");
boolean headless = GraphicsEnvironment.isHeadless();
but still my problem is not resolved? Any inputs? Should i not be using JOptionPane in a web application? if not then what is a better option? alternate of JOption?
You absolutely cannot use a JOptionPane in a web application. And don't even think of using any other of the JWhatever classes in Swing.
JOptionPane, and various other Swing components, appear only on the machine they are running on. So, even if you could get past the exception you are encountering, and display the JOptionPane somehow, the JOptionPane would appear on the server1. It would not appear in the user's browser, so the user wouldn't see it.
So, suppose this JOptionPane has appeared on the server. How is a user supposed to read it, or dismiss it? All they have access to is their browser.
The simple answer is that they can't.
Worse still, JOptionPanes are modal, in that the call to create them doesn't return until the dialog is dismissed. If a user entered a model number that did not exist, your web application would appear to hang, as it could not finish serving the page until the JOptionPane was dismissed. With a few more users using your system, the entire application would eventually grind to a halt as more and more of the web application's worker threads get stuck waiting for JOptionPanes to be dismissed.
Instead, you need to send the error message back to the browser somehow.
If the user enters a model number that does not exist, I would recommend redirecting back to the page where the model number is entered, and showing on this page a message that makes it clear to the user that they were redirected back because they entered a nonexistent model number.
Your code may have been working for you on your machine, but that would only have been because you were browsing your web application from the same machine that the web server was running on.
1: Technically you could show this JOptionPane to a client if you had an X server on the client machine and could set it up as Jim Garrison describes, but that is most certainly not something you can assume.

Can you communicate with a browser window, after opening it with a JavaFX app?

My question is just as the title indicates.
I have a JavaFX app, and need to open a browser window. After opening it, I want to be able to communicate from the browser back to the app that opened it.
For example, if I opened the default browser window like this:
URI u = new URI(url);
java.awt.Desktop.getDesktop().browse(u);
Three options:
Through Javascript
Using javascript, and the window name you could access any window.
E.g. See: https://stackoverflow.com/a/16525481/1688441
Through Ajax Calls and a Server/Database
As another user answered, communication could be done with an intermediate server.
Third party library
The only other thing I can think of is using a 3rd party library to get the window within Operating System, though not much more I can suggest.
You can communicate back and forth with a WebView component. See http://docs.oracle.com/javafx/2/webview/jfxpub-webview.htm
If you are launching a page in the hosts browser, you'll need to develop a server based method to communicate.

call gui from JSP?

I am currently learning JSP and Java Servlets. I was wondering if there is any way to call a java GUI from a JSP, not necessarily to load into the page, but to load onto the screen for database input. I am struggling trying to find some reference on how to do this on the net, but no luck so far.
You could use Java Webstart to start up the application on the client side. Or, ask the user to install a local client differently (like a daemon service).
The "GUI application" must have some kind of RPC (=remote procedure call) service running in background.
Once the client has your gui application installed, the JSP can invoke urls on http://localhost:port (ajax would help sending messages to the GUI application). The GUI application must have some rpc system (rest, webservice) that receives the requests from your web application (your jsp app) and start the GUI requested by the URL.
The problem here is to make sure the client has the port of choice available.
Another possibility is to register some URL to your application in the client side, so that when the user clicks a url like myapp://form/123 the OS automatically invokes your application to handle that URL. This kind of thing must be done differently per operating system. It's the way it works when you click on a magnet link or a skype://link. The procedure to register urls in the operating system is different per OS, you need to do some research (I never did that, but I am sure it is possible). You can also register a file extension to your app, and make sure that the specified extension is registered to your app. When the browser downloads the file and opens it, your app is invoked with the file downloaded as parameter (which will contain the instruction for your GUI). But most browser will not start automatically the app associated to the file after the download: again, you need to do some tricks on the client's operating system to make the "download and open" the default behavior for the browser.

Java: Control browser through Process

I'm remote controlling a Java application on a PC through an Android phone, and I needed my application to open a browser at the phones command, chrome in this case. I created a "Process" for chrome, opening a certain address. However, I need to be able to give tools on the Android phone for controlling the web page, such as scrolling. Can I programmatically send a command for chrome to scroll from my PC application containing the Process?
Sorry, it may have been unclear, but the only connection the android phone has to the program is through a socket. It is only used as a remote control for another Java application on a PC, which has its own screen.
I do not think that clean solution exists.
But I can suggest the following directions:
(1) try to investigate the native chrome API. If it has such ability call it with JNI.
(2) Try to use class java.awt.Robot. It allows to simulate user's activity, e.g. mouse clicks. Unfortunately it does not allow you to find any window outside your application, so it is a problem to decide where to perform the click.
(3) You can create proxy server and make browser you open to go to the target URL through the proxy. The proxy server will insert into the page your javascript that will communicate with server. The application that opens browser will send commands to server. The javascript that you inserted will receive these commands using AJAX and perform them. JavaScript can scroll browser window, so theoretically you can implement this.
If you can target the tab you want to control and edit the address bar you could send the command 'javascript:scrollTo(x, y)'. I just tested it on this page and it seems to work fine, replacing what I typed with the original address of the page.
Can I programmatically send a command for chrome to scroll from my PC
application containing the Process?
Not directly. What you could do is make some sort of web service that sits between the Android client and page that the Android client can send commands to and the page can periodically poll via AJAX calls to see what the client wants. That would be a clean DIY way that would work on other browsers besides Chrome.
You can use vnc viewer applications for that.
http://code.google.com/p/android-vnc-viewer/

WebBrowser1 problem with external web app

the external Application works good in IE so i know the problem is inside My App.
The external web app is java applet and java script based, and the problem im experiensing is when the java applet tryes to run a java script. The Applet opens a seconday window with a java script and tryes to do some operations but then i just stops. And my Application seems to be non responsive and i have to restart it.
in IE it works just fine, the java applet opens the window does its thing and updates back in to the Applet.
anyone know why it not working in the webBrowser control?
Two scenerio could be possible:
1) whenever we opens the web site in web browser control any previous session(authentication) cookie is not being reused, and new session will be created.
2) you have to override the eventhandler webBrowser_newWindow to allow opening the new window.

Categories