Camposha
  • Home
  • Android
  • Buy Projects
  • My Account
    • Become a Member
    • Log In|Log Out
    • Free Projects
No Result
View All Result
Camposha
  • Home
  • Android
  • Buy Projects
  • My Account
    • Become a Member
    • Log In|Log Out
    • Free Projects
No Result
View All Result
Camposha
No Result
View All Result
ADVERTISEMENT
Home Java

JavaFX – Create Beautiful Email Form

2 years ago
in Java
Reading Time: 2min read
39 2
A A
41
SHARES
4.1k
VIEWS
Share on FacebookShare on Twitter
ADVERTISEMENT

SimilarPosts

Java Iterator

Java Iterator

2 years ago
4k
Java Iterable Interface

Java Iterable Interface

2 years ago
4k
Java Control Structures – Loops Introduction

Java Control Structures – Loops Introduction

2 years ago
4k
Java Operators – Logical Operators

Java Operators – Logical Operators

2 years ago
4k

JavaFX Create Email Form 

This is a practical tutorial in which we see how to create a beautiful email sending form using the following controls:

  1. ComboBox – Custom editable and non-editable comboboxes.
  2. TextField – To display the email subject.
  3. Labels – To show various captions and notification when email is sent.
  4. TextArea – To allow user to type the email message.
  5. Button – To simulate sending email when clicked.

Let’s start.

Video Tutorial

Here’s the video tutorial:

Demo

JavaFx Email Form
JavaFx Email Form

EmailForm.java

This is the only file and class we need.

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
 
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.util.Callback;
 
public class EmailForm extends Application {
    final Button sendBtn = new Button("Send");
    final Label notification = new Label();
    final TextField subject = new TextField("");
    final TextArea text = new TextArea("");
 
    String address = " ";
 
    /**
     * The JavaFX Application's start() method. The enty point to JavaFX appllication.
     */
    @Override
    public void start(Stage stage) {
        stage.setTitle("Email Form App");
        Scene scene = new Scene(new Group(), 500, 270);
 
        final ComboBox emailComboBox = new ComboBox();
        emailComboBox.getItems().addAll("albert.einstein@gmail.com", "janet.reny@yahoo.com",
                "emily.njeri@qmail.com", "harry.doyle@gmail.com", "kelly.billy@hotmail.com");
 
        emailComboBox.setPromptText("Email address");
        emailComboBox.setEditable(true);
        emailComboBox.setOnAction((Event ev) -> {
            address = emailComboBox.getSelectionModel().getSelectedItem().toString();
        });
 
        final ComboBox priorityComboBox = new ComboBox();
        priorityComboBox.getItems().addAll("Highest", "High", "Normal", "Low", "Lowest");
        priorityComboBox.setValue("Normal");
        priorityComboBox.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
            @Override
            public ListCell<String> call(ListView<String> param) {
                final ListCell<String> cell = new ListCell<String>() {
                    {
                        super.setPrefWidth(100);
                    }
 
                    @Override
                    public void updateItem(String item, boolean empty) {
                        super.updateItem(item, empty);
                        if (item != null) {
                            setText(item);
                            if (item.contains("High")) {
                                setTextFill(Color.RED);
                            } else if (item.contains("Low")) {
                                setTextFill(Color.GREEN);
                            } else {
                                setTextFill(Color.BLACK);
                            }
                        } else {
                            setText(null);
                        }
                    }
                };
                return cell;
            }
 
        });
 
        //simulate sending the email
        sendBtn.setOnAction((ActionEvent e) -> {
            if (emailComboBox.getValue() != null && !emailComboBox.getValue().toString().isEmpty()) {
                notification.setText("Your message was successfully sent" + " to " + address);
                emailComboBox.setValue(null);
                if (priorityComboBox.getValue() != null && !priorityComboBox.getValue().toString().isEmpty()) {
                    priorityComboBox.setValue(null);
                }
                subject.clear();
                text.clear();
            } else {
                notification.setText("Please select a recipient first!");
            }
        });
 
        GridPane grid = new GridPane();
        grid.setVgap(4);
        grid.setHgap(10);
        grid.setPadding(new Insets(5, 5, 5, 5));
        grid.add(new Label("To: "), 0, 0);
        grid.add(emailComboBox, 1, 0);
        grid.add(new Label("Priority: "), 2, 0);
        grid.add(priorityComboBox, 3, 0);
        grid.add(new Label("Subject: "), 0, 1);
        grid.add(subject, 1, 1, 3, 1);
        grid.add(text, 0, 2, 4, 1);
        grid.add(sendBtn, 0, 3);
        grid.add(notification, 1, 3, 3, 1);
 
        Group root = (Group) scene.getRoot();
        root.getChildren().add(grid);
        stage.setScene(scene);
        stage.show();
 
    }
    /**
     * Main method. Launch our JavaFX application here.
     */
    public static void main(String[] args) {
        launch(args);
    }
 
}
 
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
Share16Tweet10Send
ADVERTISEMENT

Related Posts

Java Iterator
Java

Java Iterator

December 19, 2020
4k
Java Iterable Interface
Java

Java Iterable Interface

December 19, 2020
4k
Java Control Structures – Loops Introduction
Java

Java Control Structures – Loops Introduction

December 19, 2020
4k
Java Operators – Logical Operators
Java

Java Operators – Logical Operators

December 19, 2020
4k
Java Operators – Relational Operators
Java

Java Operators – Relational Operators

December 19, 2020
4k
Java URI
Java

Java URI

December 19, 2020
4k
ADVERTISEMENT

Get Free Projects

  • Home
  • Android
  • Buy Projects
  • My Account

© 2021 Camposha

No Result
View All Result
  • Account
  • Activate
  • Activity
  • Become a Teacher
  • Become a Teacher
  • Become a Teacher
  • Become instructor
  • Blog
  • Blog
  • Cancel Payment
  • Cancel Payment
  • Cart
  • Change Password
  • Change Password
  • Checkout
  • Checkout
  • Checkout
  • Contact
  • Contact
  • Contact Us
  • Content restricted
  • Course Checkout
  • Dashboard
  • Edit Profile
  • Edit Profile
  • FAQs
  • Forgot Password
  • Forgot Password
  • Guest
  • Guest
  • Home
  • Home
  • Home Light
  • Instructor Dashboard
  • Instructor Registration
  • IUMP – Account Page
  • IUMP – Default Redirect Page
  • IUMP – Login
  • IUMP – LogOut
  • IUMP – Register
  • IUMP – Reset Password
  • IUMP – TOS Page
  • IUMP – Visitor Inside User Page
  • List courses
  • List wish list
  • Login
  • Login
  • Maintenance
  • Members
  • Membership Account
    • Membership Billing
    • Membership Cancel
    • Membership Checkout
    • Membership Confirmation
    • Membership Invoice
    • Membership Levels
  • Membership Account
    • Membership Billing
    • Membership Cancel
    • Membership Checkout
    • Membership Confirmation
    • Membership Invoice
    • Membership Levels
  • Membership Plans
  • My Account
  • OnePage Documentation
  • Portfolio Grid
  • Portfolio Masonry
  • Portfolio Multigrid
  • Privacy Policy
  • Products
  • Profile
  • Profile
  • Profile
  • Projects
  • Register
  • Register
  • Register
  • Register
  • Sample Page
  • Shop
  • Sign in
  • Sign up
  • Student profile
  • Student Registration
  • Thank You
  • Thank You

© 2021 Camposha

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms below to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In