Search This Blog

Showing posts with label javafx. Show all posts
Showing posts with label javafx. Show all posts

JavaFX Development: Install e(fx)clipse plugin for Eclipse

Develop JavaFX application using eclipse, you may experiencing this error:
Access restriction: The type Pane is not accessible due to restriction on required library C:\Program Files\Java\jre8_0\lib\ext\jfxrt.jar


There are a few ways to resolve this issue. The easiest solution is to install e(fx)clipse plugin.
  1. Find the latest release, by opening web page: https://download.eclipse.org/efxclipse/updates-released
  2. In Eclipse (Mac OS), Help => Install New Software... => Add site: https://download.eclipse.org/efxclipse/updates-released/3.5.0/site
  3. Check 'e(fx)clipse -install' and click Next button to install.

Enable iglx on Mac OS (XQuartz) or Linux for JavaFX Applications

When executing a Java FX application on a remote SSH server by forwarding display to local X11(XQuartz), I got this error:

libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  149 (GLX)
  Minor opcode of failed request:  24 (X_GLXCreateNewContext)
  Value in failed request:  0x0
  Serial number of failed request:  25
  Current serial number in output stream:  26

searched and found this solution: https://github.com/ControlSystemStudio/cs-studio/issues/1828


Solution:

  • On Mac OS(XQuartz), execute the command below in Terminal:
    defaults write org.macosforge.xquartz.X11 enable_iglx -bool true
    and restart X11(XQuartz)
  • On Linux, try this


see also

JavaFX WebView shows blank page when the web site ssl certificate is not trusted ( or self-signed)

JavaFX WebView shows blank page when the web site ssl certificate is not trusted (or self-signed). There is not errors/exceptions that you can see unless you set up a listener before you load the web site in WebView: The following code will show the error:
    WebView web = new WebView();
    web.getEngine().load("https://www.your-org.org");
    web.getEngine().getLoadWorker().stateProperty()
            .addListener((ov, oldState, newState) -> {
                System.err.println(web.getEngine().getLoadWorker()
                         .exceptionProperty());
            });
The error is like below:
java.lang.Throwable: SSL handshake failed
To resolve the error, if you trust the web site, you can ignore the error by adding following code before you start the WebView:
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] { 
    new X509TrustManager() {     
        public java.security.cert.X509Certificate[] getAcceptedIssuers() { 
            return null;
        } 
        public void checkClientTrusted( 
            java.security.cert.X509Certificate[] certs, String authType) {
            } 
        public void checkServerTrusted( 
            java.security.cert.X509Certificate[] certs, String authType) {
        }
    } 
}; 

// Install the all-trusting trust manager
try {
    SSLContext sc = SSLContext.getInstance("SSL"); 
    sc.init(null, trustAllCerts, new java.security.SecureRandom()); 
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (GeneralSecurityException e) {
}

WebView web = new WebView();
web.getEngine().load("https://www.your-org.org");
NOTE: After executing the above code, your application will trust all https web sites. To have a more secure solution, you may maintain a local key store to add the trusted certificates, see this for more detail.

See also

JavaFX: how to use ListProperty?

when adding element to ListProperty, like below:
ListProperty<String> members = new SimpleListProperty<String>();
members.add("John");
members.add("David");
it throws UnsupportedOperationException
java.lang.UnsupportedOperationException
  at java.util.AbstractList.add(AbstractList.java:148)
  at java.util.AbstractList.add(AbstractList.java:108)
  at java.util.AbstractCollection.addAll(AbstractCollection.java:334)
  at javafx.beans.binding.ListExpression.addAll(ListExpression.java:280)
The problem was that the ListProperty was not properly initialized. To make it work, see the following code
ObservableList<String> observableList = FXCollections.observableArrayList(new ArrayList<String>());
ListProperty<String> members = new SimpleListProperty<Priority>(observableList);
members.add("John");
members.add("David");







see also

JavaFX: Add CSS to TreeTableView

treeTableView.getStylesheets().add("myStyles.css;");

JavaFX TreeTableView set font weight of a TreeTableColumn

Create a css file:
column.setStyle("-fx-font-weight: bold;");

Make Papaya Javascript DICOM viewer work in JavaFX WebView

When loading Papaya Javascript DICOM/NIFTI Viewer in a JavaFX WebView, it failed with error message:
Papaya requires Safari version 6 or higher.
So I checked WebKit version of JavaFX 8 using the following code:
WebView web = new WebView();
System.out.println(web.getEngine().getUserAgent());
it shows the JavaFX 8 WebKit UserAgent information:
Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/538.19 (KHTML, like Gecko) JavaFX/8.0 Safari/538.19
According to Safari version history, Safari 6.0 is based on WebKit 536.25, while Webkit in JavaFX 8 is 538.19. WebKit in JavaFX 8 is above Safari 6.0. The problem is the browser detection in Papaya could not detect the version. So the work around is to modify the Papaya source code to accept JavaFX 8 WebKit agent.
  1. Check out Papaya js:
    git clone https://github.com/rii-mango/Papaya.git
  2. Edit src/js/utilities/platform-utils.js, insert the following code:
    papaya.utilities.PlatformUtils.checkForBrowserCompatibility = function () {
        if (navigator.userAgent.indexOf('JavaFX')>=0) {
            return null;
        }
       ... ... ...
    }
    
  3. Download and build Papaya-builder, then install it into Papaya/lib/:
    git clone https://github.com/rii-mango/Papaya-Builder.git
    cd Papaya-Builder
    ant
    cp build/papaya-builder.jar ../Papaya/lib/
    
  4. Build Papaya:
    cd Papaya
    ./papaya-builder.sh
    ls build/
    

JavaFX: load css from file

  • load from relative path:
     // the java class is in the same directory as the .css file.
    String css = getClass().getResource("MyApp.css").toExternalForm();
    scene.getStyleSheets().add(css);
    
  • load from absolute path:
    // the .css file is stored under <ROOT>/css/ directory.
    String css = getClass().getResource("css/MyApp.css").toExternalForm(); 
    scene.getStyleSheets().add(css);
    

JavaFX: Show grid lines of TreeTableView

  • Save the following to resources/MyApp.css:
    .tree-table-row-cell {
        -fx-background-color: -fx-table-cell-border-color, -fx-control-inner-background;
        -fx-background-insets: 0, 0 0 1 0;
        -fx-padding: 0.0em;
        -fx-text-fill: -fx-text-inner-color;
    }
    .tree-table-row-cell:selected {
        -fx-background-color: -fx-focus-color, -fx-cell-focus-inner-border, -fx-focus-color;
        -fx-background-insets: 0, 1, 2;
    }
    
    .tree-table-row-cell:odd {
        -fx-background-color: -fx-table-cell-border-color, derive(-fx-control-inner-background,-5%);
        -fx-background-insets: 0, 0 0 1 0;
    }
    
    .tree-table-row-cell:selected:odd {
        -fx-background-color: -fx-focus-color, -fx-cell-focus-inner-border, -fx-focus-color;
        -fx-background-insets: 0, 1, 2;
    }
    
  • In your Java class, add the css to a scene.
    String css = getClass().getResource("/resources/MyApp.css").toExternalForm();
    scene.getStyleSheets().add(getClass().getResource(cs);