Hey everyone.

So I'm trying to create a siple text editor for handling HTML. I got the majority of the program written to where when you click the toolbar the text is inserted. The only problem is that it only inserts it at the end. So Now I'm trying to insert text around a selection and where the curser is location.

I got the tags to be able to be inserted around a selection but how do I do where the cursur is located? Would that be done with a focus statement?

Here's my method:

private void boldButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
    if (textArea.getSelectedText().isEmpty()) {
        textArea.setText(textArea.getText() + "<b></b>");
    } else {
        textArea.insert("<b>", textArea.getSelectionStart());
        textArea.insert("</b>", textArea.getSelectionEnd());
    }
}   

Any help is appreciated since I can't find exactly what I'm looking for from searching here and the web.

Recommended Answers

All 2 Replies

getCaretPosition() ?

i tried that. still, the problem is, i only want to place at caret postion if there is nothing selected. sorry, i should have explained that earlier.

so i have my if else statement but i can't find any property that returns a boolean to check if selectiion. if it's out there i am having trouble finding it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.