Code example for JTextComponent

Methods: putClientPropertygetDocument

0
 
        return spans;
    } 
 
    public static void setSelection(JTextComponent target, List<DocumentSpan> updatedSelection) throws BadLocationException {
        Document document = target.getDocument();
 
        if (updatedSelection.size() > 1 && !isRectangularSelection(target)) {
            setRectangularSelection(target, true);
        } 
 
        if (updatedSelection.size() > 1) {
            List<Position> positions = new ArrayList<>();
            for (int i = 0; i < updatedSelection.size(); i++) {
                positions.add(document.createPosition(updatedSelection.get(i).getStart().getOffset()));
                positions.add(document.createPosition(updatedSelection.get(i).getEnd().getOffset()));
            } 
 
            target.putClientProperty(RECTANGULAR_SELECTION_REGIONS_PROPERTY, positions);
        } else { 
            target.select(updatedSelection.get(0).getStart().getOffset(), updatedSelection.get(0).getEnd().getOffset());
        } 
    } 
 
Connect your IDE to all the code out there  Get Codota for Java