Vaibhav's Blog Space

  • Java
    December 6, 2008

Mobile + Desktop JavaFX !

Guest Author

Just want to put the attention on one important point regarding the coding in JavaFX. Everyone who is using JavaFX has to understand that this technology is supported on Mobile, Desktop and TV(tomorrow it will be). So, its important as a developer to write Generic Applications which run across the platform. In such cases you need to know how to adjust some silly things in the code, like so desktop it can be a big font whereas you need to reduce font size for mobile or same case with images. 

Here is one sample code, which can show you how to do :

package sample11;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
var mobile = FX.getProperty("javafx.me.profiles");
var isMobile = (mobile != null);
var s = 24;
var content = "Default";
if(isMobile == true) {
    s = 10;
    content = "Content in Mobile"
else {
    s = 20;
    content = "Content on Desktop"
Stage {
    title: "Checking the Font"
    width: 350
    height: 280
    scene: Scene {
        content: Text {
            font : bind Font {
                size : s
            x: 10, y: 30
            content: bind content

Run it on Desktop and on Mobile and see the different output.

(How to run on Mobile ? ---> Netbeans6.5 -> YourProject -> Right Click ->Properties -> Run -> Run as Mobile Emulator)

This feature has been nicely used in this sample :  InterestingPhotos.

Join the discussion

Comments ( 2 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.