File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Grouping text in JTextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Grouping text in JTextArea" Watch "Grouping text in JTextArea" New topic

Grouping text in JTextArea

Richard Robbins
Ranch Hand

Joined: Mar 07, 2001
Posts: 66
I am writing an application using a JTextArea, and I need to group text together so that a whole section is treated as a single object. I am creating messages which can have parameters substituted into them. These parameters are kept in a JComboBox. For instance, a message could look like this:
Hello <salutation> <lname>...
The parameters (salutation and lname) would be entered by selecting the parameter from the JComboBox and clicking a JButton, whereupon the parameter is entered into a message. I need a mechanism such that if a user decides to remove the parameter, he can move the cursor to the end of the parameter and hit backspace, and the whole parameter will be removed. In other words, this should not be possible:
Hello <salut... >
because the <salutation> parameter is grouped together and treated as if it were a single character/object. Any ideas?

Richard Robbins is one of the founders of, a resource for free website templates and Photoshop tutorials. He also consults for an online boutique selling baptism dresses and christening gowns.
I agree. Here's the link:
subject: Grouping text in JTextArea
It's not a secret anymore!