Skip to main content

An Example to JavaFX

Hi Friends,
In previous post i was provided you an small introduction to JavaFX. Lets see an example based on JavaFX. Hope you have downloaded and setup IntelliJ Idea IDE.

Note: This example is based on only java classes(Pure java Example).

Setting up the JavaFX project(Gradle based)


  1. Go to File-> New-> Project and click.One popup dialog will appear.
  2. On left panel of dialog, click on gradle.
  3. On right panel you will see some check boxes. Select Java and click Next.
  4. You will asked to fill some text fields.
  5. Enter project's package name in GroupId(i.e com.coderzduniya.fxdemo).
  6. Enter project name in ArtifactId(i.e JavaFX Demo).
  7. Leave Version as it is and go to Next.
  8. Go to Next again and Finish.
  9. After doing it well your project will be created.







  • Now right click on java folder inside src/main and go to New-> JavaFXApplication
  • Enter the class name(i.e Main) and click OK.

Now copy the following code and paste inside your start method(Method start(...) will be created automatically).

I have explained the structure and Code flow in video tutorial.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 //Base Container
        final GridPane root = new GridPane();

        //Positioning contents
        root.setHgap(15);
        root.setVgap(15);
        root.setAlignment(Pos.CENTER);

        //Creating User name fields
        final Label labelUserName = new Label("UserName:");
        final TextField tfUserName = new TextField();

        //Creating password fields
        final Label labelPassword = new Label("Password:");
        final TextField tfPassword = new TextField();

        //Creating button
        final Button btnOK = new Button("Click Me");
        btnOK.setAlignment(Pos.BOTTOM_RIGHT);

        //Adding contents to the root
        root.add(labelUserName, 0, 0);
        root.add(tfUserName, 1, 0);
        root.add(labelPassword, 0, 1);
        root.add(tfPassword, 1, 1);
        root.add(btnOK, 1, 3);

        //Creating a window on which root will be displayed with provided width and height
        final Scene scene = new Scene(root, 400, 300);

        //Set scene to the stage
        primaryStage.setScene(scene);

        //Set app title
        primaryStage.setTitle("JavaFX Demo");

        //Show/Launch the app
        primaryStage.show();

        //Adding click listener to button
        btnOK.setOnAction(event -> System.out.println("Button clicked!"));


This is a basic example of JavaFX. Hope this will be helpful to you.
Keep reading my blog and send me your suggestions. Thankx :)

Comments

Popular posts from this blog

JavaFX WebView- Creating Browser Sample

Hi Friends, In this post, i am going to give an overview about JavaFX WebView . This is an embedded browser component which is based on WebKit . If allow you to use Css, JavaScript, HTML5 and more to customise your embedded browser. The embedded browser enables you to perform the following tasks in your JavaFX applications: Render HTML content from local and remote URLs Obtain Web history Execute JavaScript commands Perform upcalls from JavaScript to JavaFX Manage web pop-up windows Apply effects to the embedded browser  I am going to provide and explain you a sample example to create your embedded browser. This is a JavaFX sample example. if you want to take an introduction about JavaFX please visit my previous blog . I have use IntelliJ Idea IDE for this example. You can visit this link  to understand how to create JavaFX application. I am attaching the project structure image below- In this sample- we have two java class. First

Working with MPAndroidChart (how to create Bar Chart using MPAndroidChart)

Hi Friends, In this tutorial i am going to show, "How to create Bar Chart using MPAndroidChart". There is a lot of libraries for creating charts in android like AChartEngine, MpAndroidChart, AndroidPlot etc. Your first question may be, Why MPAndroidChart. So MpAndroidChart provides better animation functionality and easy to use in comparision. Using  MPAndroidChart library  we can draw a: ·          Simple Bar Chart ·          Grouped Bar Chart ·          Horizontal Bar Chart ·          Simple Line Chart ·          Line Chart with Cubic Lines ·          Grouped Line Chart ·          Combined Line and Bar Chart ·          Pie Chart ·          Scatter Chart ·          Candlestick Chart ·          Radar Chart Here we will create Simple Bar Chart with multiple color based on ranging. Ok We start with coding part now. First of all create your project in Android Studio and add gradle dependency for  MPAndroidChart library  into y

app-policy

PRIVACY POLICY Last updated April 19, 2023 This privacy notice for Team CoderzDuniya ( " Company ," " we ," " us ," or " our " ), describes how and why we might collect, store, use, and/or share ( " process " ) your information when you use our services ( " Services " ), such as when you: Download and use our mobile application ( Revenue Calculator) , or any other application of ours that links to this privacy notice Engage with us in other related ways, including any sales, marketing, or events Questions or concerns?  Reading this privacy notice will help you understand your privacy rights and choices. If you do not agree with our policies and practices, please do not use our Services. If you still have any questions or concerns, please contact us at droidamar007@gmail.com . SUMMARY OF KEY POINTS This summary provides key points from our privacy notice, but you can find out more details about any of these t