But my problem is in adding scroll bar to JPanel which is placed over a JDialog.
You have just been given a ready made solution. Did you even bother to try and run the code? If yes, did you observe the output? If yes did you notice the red and blue background? Did you notice the scroll bars? Is it so complicated that you are unable to comprehend ~22 lines of code?