Trouble with text boxes

Hey guys, is there a common way to handle text boxes easily in java?
I’m making a sort of RPG and of course you’ll need to be able to walk up to NPCs and talk to them.
I’m thinking of using a traditional textbox…the best example I could think of is like the textboxs in the pokemon games. Where it shows a few lines of text and then you press a button to go to the next few lines of text. A scroll box would be nice, but it doesn’t really matter to me.

Anyways my current idea is a mess.
Right now I’m trying read the text one word at a time and storing each word into a variable like word1,word2,word3,word4,word5 and making another variable thats is for lines, such as line1,line2,line3, where the first 5 words go into line1, the next 5 go into line2 and the next 5 go into line3.
After that if a button is pressed than it starts drawing the next few lines until there’s no text.

Anyways like I said, I feel like I’m doing it pretty backwards and came here to see if there’s an easier method to all this. (: thanks!