How does Eclipse show the startup interface so fast - java

Java programs start slowly.
I program a JavaFX desktop software. When I double click the executable jar, it costs nearly 5 seconds to show the window. I think the JVM spends a little time to load the class.
But when I open Eclipse, the progress GUI is showed immediately. How can I do that like Eclipse? Does it use other technology to show the GUI without JVM?

The 'eclipse' executable is actually a small C program (source code is here).
This reads the eclipse.ini, displays the splash screen if it is specified and then initializes the JVM using the parameters specified in the eclipse.ini and starts the main Eclipse Java code. So the JVM initialization and Java startup is done with the splash screen already displayed.
The Java code is given a reference to the splash window so it can update the progress and close the window when done.
If you write an Eclipse RCP the same code is used to start your RCP.

The secret is: which classes are used to display that "splash screen"?!
Guessing here: the eclipse people have fine-tuned that code. It might be possible that they use AWT only components there. Well, I stay corrected: they are not using java at all for the splash screen (see the other answer). No surprise.
Beyond that, anecdotal answer on splashing with Java: many years ago I wrote a Swing application. Of course, the customer wanted a nice splash screen, with the company logo and a progress bar; showing the amount of loaded "modules". I coded the first version using swing panels. That panel came up after 15 seconds (no SSDs back then), and 3 seconds later, 100% were reached. Solution back then: I wrote a new version that went with a minimal number of AWT components. In the end, that splash screen looked a little bid "less nice" - but it came up after say 3, 5 seconds.
I think I even tampered with class loading order to ensure that all "expensive" classes were loaded after I pulled the stuff required to show the splash screen.
( and in case this doesn't result in "enough delay" between "splash showing up" and "application fully loaded" ... one could simply extend the "life time" of the splash screen by simply having it sit there a bit longer. sure, you don't tell the customer about that ;-)

Related

Java Swing HiDPI Scaling

I have created a program using Java 8 that utilises a Swing GUI in the Eclipse IDE. To scale images and icons to appropriate sizes, it gets and uses the screen resolution. Upon compiling the program within Eclipse, the program displays perfectly fine, and everything seems to operate as it should. However, when I export the project as a "Runnable Jar", and run the program, the image scaling and the program look and feel are all off.
Upon further investigation, it appears that the runnable jar was returning a screen resolution that is exactly 2.5x less then that in eclipse (which is the actual resolution - 3840x2160 vs 1536x864). There is circumstantial evidence across the internet that Java 8 Look and Feels (or something of the sort) don't support HiDPI screen scaling. There are scattered solutions that claim to fix the problem, like updating to Java versions past 8, or by adding arguments to the jar compilation (whatever that means). This is already confusing to a Java novice, and it is only made more confusing by the program being displayed perfectly when run/compiled within the Eclipse IDE.
My question is whether anyone knows how to get a program compiled in Java using Swing to scale correctly on an HiDPI screen, and what the process is that I need to follow to compile a working program?
EDIT 1: Something interesting to note is that in my Windows settings, the "Scale and Layout", "Change the size of text, apps, and other items" is set to exactly 250%, meaning that this setting is obviously the cause of the scaling issues I am encountering. Does someone know how to bypass this setting from within the program, or why it works when I run it through Eclipse?
Java 8 does not support High DPI. On Windows, it runs in DPI unaware mode and relies on Windows to stretch the window bitmap to the scale set for the monitor in the settings. It means the UI of the application looks blurry when displayed on a High DPI monitor.
Later versions of Java, Java 11 and above, support per-monitor High DPI settings. The UI of your application is correctly scale up according to the settings, the text remains crisp. For the icons and images to remain crisp, you should use MultiResolutionImage or its basic implementation BaseMultiResolutionImage to provide higher resolution alternatives.
You should not base your images based on the screen resolution but rather on the scale set for a monitor. For example, a Full HD monitor 1920×1080 with 150% scale has the effective resolution 1280×720, it is the effective resolution that Java reports to you.

A set of mouse/keyboard actions Java program

I want to build a program that does the following:
User clicks on a button (like on a GUI) to record his/hers movements.
Then, the user does a set of actions on the computer - this could be clicking on file explorer and deleting/creating/renaming a file, opening Chrome or another program etc... basically a few keyboard/mouse movements.
Then the user can specify a time at which the program should replicate this recording of movements. (The program hasn't been stopped and it uses the current time of the computer's clock to know when to do it)
Can I do something like this in Java? Searched quite a bit and couldn't see something relevant. The only thing that came to my mind since I am still a beginner is MouseEvents etc but I don't think these can be done outside the frames of GUI.
Thanks in advance I am keen to build this project!
JNativeHook is worth looking into for this and similar purposes. I found it helpful.
https://github.com/kwhat/jnativehook

Java application drawing strangely

I have a legacy Java application that uses Java 1.3
It works fine on windows Xp but now I need to make it run on windows 7.
I have installed the 1.3 jdk however when it first loads, the app won't render properly. Bits of the screen just show grey background, selecting buttons won't load a new screen etc.
I do know watching the output from the app it just purely graphics not rendering properly.
However if I press "Ctrl-alt-delete" and then just press "cancel" the software runs perfectly.
If I have a second monitor plugged in, it runs perfectly.
Has anyone got any suggestions how to make app run perfectly first time.
Thanks
Firstly, update your java, no excuses not to.
You can try the hack of resizing your component to a different size and then back again. I find this is the best way to make sure that swing doesn't do this sort of mischief with black squares here and there.
These things happen from time to time with non native tools for desktop development as opposed to those specifically designed for the targeted platform.

Java applet doesn't fully refresh

I've been working on a game that's played in a java applet. It all works fine, until you try to refresh the page. It often seems to 'keep' the applet it used so far, and relaunches the game in the same applet. A new process is not created, and the ram usage shoots up (~250mb instead of ~140mb), and the same console is used for the applet. The drawing process is also quite laggy; it often skips about 0.5 seconds of frames before drawing again.
It only sometimes completely refreshes the applet; a new process is created (as seen in Windows' task manager), a new console opens, it uses less ram; it just starts from scratch again.
As I experience issues when it reuses the applet, I would like to force it to create the new process every time I refresh. Is there a way to do that? Or can I somehow fix the issues when it doesn't completely refresh?
The game I'm working on can be seen at http://patrickdev.nl/galaxy048/. Once it runs, press 'f' to toggle the fps and memory details.
Thank you in advance.
Applets support a parameter that force it to run the applet in a new jvm. This also works after refreshing the page, and is exactly what I was looking for - it starts from scratch. Just add this parameter to your applet tag:
<param name="separate_jvm" value="true" />
More information at http://www.oracle.com/technetwork/java/javase/plugin2-142482.html#SEPARATE_JVM

Recommended technology choice for desktop application

I am creating an application that is essentially a financial alerts site. I am a basic level Java programmer, and I have created some of the logic for alerts in Java.
I want to be able to have pop-ups appear on the desktop whenever something "interesting" happens (interesting depends on %change, liquidity and a few other simple factors).
What is the best combo of technology to implement something like this?
I would use the java.awt.SystemTray in Java SE 6. It's cross-platform and pretty easy to use.
Although some people hate the balloon notifications in Windows, they're the least obtrusive popups, since they can be ignored by the user or easily dismissed. Most importantly, they can't be missed by the user who has been away from the computer, because balloons (at least in Windows XP/Vista) use system idle timers to determine when's the right time to disappear.
Some prefer more traditional toast notifications, similar to those shown by Outlook - they show up and slowly fade out, giving the user some time to interact with them if needed.
I had the same problem and finally solved it using an undecorated, alwaysOnTop window.
And thanks to this blog entry I found the TimingFramework, and now it even is translucent, fades in and out, goes 100% opaque on mouse over etc. In conjunction with the SystemTray and TrayIcon the behavior is nearly as that of Outlook.
Oh, I have to note, that other than the second link, I do the fading out with
AWTUtilities.setWindowOpacity(window, op);
You could write a java program that resides in the system tray, but I am not sure if there are cross platform compatible ways to do this. maybe you have to use a platform specific library for Win, Mac, Linux, ...
I'd just create a message window and animate it. Then add SystemTray support and voila, you're done.
In Delphi you can do that pretty quickly, but you can't easily reuse your java logic
You can just run you program in "silent" mode, without creating any windows by default, maybe just a little icon in the taskbar which when double-clicked will open a settings window. The program will be running in the background and creating windows with the set focus whenever an event happens.
But in my opinion, a slide window or at least a balloon tooltip is a better idea.

Categories