In JPanel I have written some text. I have to write it like one string and to define some logic for line break. When text comes to the width of panel, I should make line break and pass next word that can not fit in line to the new line.
Check out FontMetrics. You can get an instance through the Graphics object. This allows you to calculate the width any string would need. I'd use a loop for that. In pseudo code:
1) this will prevent you from entering an infinite loop if you have one word that simply is too long. Without it, the same word would be skipped each time and tried to be drawn on the next line, where it won't fit either.