07 January, 2015

How to close Java splash image after the application starts

There is a very easy way to get Splash screen in Java application.
With a "-splash:imagepath" command line parameter, or with "SplashScreen-Image: imagepath" manifest parameter.

But when an application is started, Java still shows this image (below the application layer, but it visible when you switching between the applications), until the application is finished. Strange behavior, but it is possible to close this kind of splash screen.

With these lines of code:
import java.awt.SplashScreen;
...
SplashScreen splashScreen = SplashScreen.getSplashScreen();
if (splashScreen != null) {
    splashScreen.close();
}

How to create a file extension association with the program in Windows

Assume that you have a program named "table-explorer.exe".
And you want to open all ".csv" and ".sas7bdat" files using  this program by default in Windows.

First you need to create a file extension association with the program via these commands:


reg add HKCU\SOFTWARE\Classes\.csv /d "table-explorer" /f
reg add HKCU\SOFTWARE\Classes\.sas7bdat /d "table-explorer" /f


And then register the application:


reg add HKCU\SOFTWARE\Classes\table-explorer\shell\open\command /d "\"C:\Path\to\table-explorer.exe\"" /f

06 January, 2015

How to bind hotkeys in Java FX

It is possible to create global keyboard shortcuts using a code like this:
import static javafx.scene.input.KeyCombination.keyCombination;
...
private void initHotkeys() {
    ObservableMap accelerators = stage.getScene().getAccelerators();
    accelerators.put(keyCombination("Alt+S"), searchTextField::requestFocus);
    accelerators.put(keyCombination("Alt+C"), columnsTextField::requestFocus);
    accelerators.put(keyCombination("Alt+O"), openFileButton::fire);
    accelerators.put(keyCombination("Alt+E"), exportButton::fire);
    accelerators.put(keyCombination("Alt+T"), truncateButton::fire);
    accelerators.put(keyCombination("Alt+H"), () -> filterChoiceBox.setValue(MATCH_HIGHLIGHT));
    accelerators.put(keyCombination("Alt+F"), () -> filterChoiceBox.setValue(MATCH_FILTER));
    accelerators.put(keyCombination("Alt+U"), () -> filterChoiceBox.setValue(MATCH_FILTER_UNIQUE));
    accelerators.put(keyCombination("Alt+D"), () -> {
        //todo some debug action
    });
}