Simple Java To-Do App with Core Features (Add/Delete/Mark Complete)

By Vandu
May 4, 2025

Follow us on


Learn how to build a basic to-do list app in Java with add, delete, and mark-as-complete functionalities. Beginner-friendly tutorial with clear code explanations.

Simple Java To-Do App with Core Features (Add/Delete/Mark Complete)

Create a To-Do List App with Add/Delete/Complete Features in Java

Managing tasks is a daily routine for many of us, and a to-do list app helps us stay organized. In this step-by-step tutorial, we will create a To-Do List App in Java using Swing — a GUI toolkit for building desktop apps.

This beginner project will help you understand:

  • GUI design using Swing

  • List data management

  • Event handling (buttons and actions)

Let’s get started!


🧱 Tools & Prerequisites

  • JDK (Java Development Kit) installed

  • Any IDE like IntelliJ IDEA, Eclipse, or NetBeans

  • Basic knowledge of Java syntax and OOP


🎯 Features of Our To-Do List App

  • Add new tasks

  • Delete selected tasks

  • Mark tasks as completed

  • View tasks in a scrollable list


🧑‍💻 Step-by-Step Code with Explanation

📂 Step 1: Create the Java Class

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;

public class ToDoListApp extends JFrame {
    private DefaultListModel<String> listModel;
    private JList<String> taskList;
    private JTextField taskInput;
    private ArrayList<Boolean> taskCompletionStatus;

    public ToDoListApp() {
        setTitle("To-Do List App");
        setSize(400, 500);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLayout(new BorderLayout());

        listModel = new DefaultListModel<>();
        taskList = new JList<>(listModel);
        taskList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        JScrollPane scrollPane = new JScrollPane(taskList);

        taskInput = new JTextField();
        JButton addButton = new JButton("Add Task");
        JButton deleteButton = new JButton("Delete Task");
        JButton completeButton = new JButton("Mark as Complete");

        taskCompletionStatus = new ArrayList<>();

        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(1, 3));
        panel.add(addButton);
        panel.add(deleteButton);
        panel.add(completeButton);

        add(taskInput, BorderLayout.NORTH);
        add(scrollPane, BorderLayout.CENTER);
        add(panel, BorderLayout.SOUTH);

        // Action to add a task
        addButton.addActionListener(e -> {
            String task = taskInput.getText().trim();
            if (!task.isEmpty()) {
                listModel.addElement(task);
                taskCompletionStatus.add(false);
                taskInput.setText("");
            }
        });

        // Action to delete a task
        deleteButton.addActionListener(e -> {
            int selectedIndex = taskList.getSelectedIndex();
            if (selectedIndex != -1) {
                listModel.remove(selectedIndex);
                taskCompletionStatus.remove(selectedIndex);
            }
        });

        // Action to mark as complete
        completeButton.addActionListener(e -> {
            int selectedIndex = taskList.getSelectedIndex();
            if (selectedIndex != -1) {
                boolean isCompleted = taskCompletionStatus.get(selectedIndex);
                if (!isCompleted) {
                    String task = listModel.getElementAt(selectedIndex);
                    task = "✔️ " + task;
                    listModel.set(selectedIndex, task);
                    taskCompletionStatus.set(selectedIndex, true);
                }
            }
        });

        setVisible(true);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(ToDoListApp::new);
    }
}

🔍 Step-by-Step Explanation

1. Imports

import javax.swing.*; // for GUI components
import java.awt.*; // for layout
import java.awt.event.*; // for button actions
import java.util.ArrayList; // to track completion status

2. Class Declaration

We extend JFrame to create a windowed app.

public class ToDoListApp extends JFrame {
 

3. UI Components

  • DefaultListModel<String>: Holds the list of tasks.

  • JList<String>: Displays the list to users.

  • JTextField: For inputting new tasks.

  • JButtons: To add, delete, and mark tasks.

DefaultListModel<String> listModel;
JList<String> taskList;
JTextField taskInput;
ArrayList<Boolean> taskCompletionStatus;

4. Layout & Panels

We use BorderLayout for the main window and GridLayout for the buttons.

setLayout(new BorderLayout());
 

5. Add Task Action

When the user enters a task and clicks "Add", we:

  • Add it to the listModel

  • Mark its completion as false

  • Clear the input field

addButton.addActionListener(e -> {
    String task = taskInput.getText().trim();
    ...
});
 

6. Delete Task Action

We delete the selected task from both the list and the status array.

deleteButton.addActionListener(e -> {
    int selectedIndex = taskList.getSelectedIndex();
    ...
});
 

7. Mark Task as Complete

We prepend a checkmark (✔️) to completed tasks and mark them as true.

completeButton.addActionListener(e -> {
    int selectedIndex = taskList.getSelectedIndex();
    ...
});
 

🧪 Output Preview

When you run the program:

  • A window opens with a text field and three buttons.

  • You can enter tasks, select them, and either delete or mark them as complete.


✅ Final Thoughts

This simple To-Do List App in Java is a great project for beginners to:

  • Practice Java Swing

  • Understand event-driven programming

  • Learn how to manipulate lists dynamically

You can further enhance this app by:

  • Saving tasks to a file

  • Adding deadlines or categories

  • Creating a dark/light theme


© 2025 Pay18News. All rights reserved.