Skip to content

paintComponent not being called during sorting #1

@dlarocque

Description

@dlarocque

In the Bubble, Insert, and Selection classes where there the sorting and painting happens, the repaint() method is called in the sort() method after each index swap.
This is supposed to update the image in the JFrame every 2ms.
Instead, repaint() does not call paintComponent a single time until the sorting is complete, showing the green sorted array.
-Tried using validate() / revalidate(), didn't work as the JFrame does not need to be invalidated as none of the components themselves change, just the array which doesn't invalidate.
-I've noticed that the repaint() method is not necessary to draw the array if we just want to display the original unsorted array. Maybe the repaint() method is never calling the paintComponent method, it's just being updated before and after the sorting method has run. We need to find a way to repaint the component during the sorting.

--The problem may be a thread issue? Have to learn about threads to try to fix the problem.

** 06/30/2020
Asked about this on Stack Overflow, an answer said i should run the sorting on a separate thread and use thread.sleep on that thread while it is repainting.
-Reading into https://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html to solve.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions