Bonjour a tous,

je souhaite modifier la position de mon curseur tout en gardant le texte que j'ai sélectionné dans mon JTextPane.

Je sais qu'il existe les méthodes :
-moveCaretPosition(int pos), qui permet de bouger le curseur tout en sélectionnant le texte sur lequel on passe.
-select(int d, int f), qui sélectionne le texte indiqué(mais place le curseur au dernier caractère)
-setCaretPosition(int pos), qui permet de placer le curseur à l'endroit indiquer(mais qui m'enlève ma sélection).

Ma question est le suivante :
comment faire pour placer le curseur au début du texte sélectionné, tout en gardant cette sélection?

Remarque :
est-il possible de faire une sélection en arrière
ex : faire un select(int f, int d) en gros? car pour moi cela ne marche pas.

voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
 
public void actionPerformed(ActionEvent e) {  
        this.document=textPaneTexte.getStyledDocument();
 
        String textSelect = textPaneTexte.getSelectedText();
        int positionStart = this.textPaneTexte.getSelectionStart();
        int positionEnd = this.textPaneTexte.getSelectionEnd();
 
        this.style=this.document.getLogicalStyle(textPaneTexte.getCaretPosition());        
 
        System.out.println(positionStart+"-"+positionEnd+"--"+textPaneTexte.getCaretPosition());
 
        if(this.textPaneTexte.getCaretPosition() == positionEnd) {
            this.textPaneTexte.setCaretPosition(positionStart);
            this.textPaneTexte.select(positionEnd,positionStart);
            System.out.println(this.textPaneTexte.getSelectedText());
        }
 
        this.attributes = new SimpleAttributeSet(this.textPaneTexte.getCharacterAttributes());
 
        System.out.println(textPaneTexte.getSelectionStart()+"-"+textPaneTexte.getSelectionEnd()+"--"+textPaneTexte.getCaretPosition());
 
        System.out.println("avant update");
        for (Enumeration en = this.attributes.getAttributeNames(); en.hasMoreElements() ;) {
            System.out.println(en.nextElement());
        }
                //JPane.getStyleDocument().setCharacterAttributes(debut,longueur,attribut_pasgras,true)
 
        if(e.getSource() == this.buttonTextAlignLeft) {
            StyleConstants.setAlignment(this.style, StyleConstants.ALIGN_LEFT);
        }
        else if(e.getSource() == this.buttonTextAlignCenter) {
            StyleConstants.setAlignment(this.style, StyleConstants.ALIGN_CENTER);
        }
        else if(e.getSource() == this.buttonTextAlignRight) {
            StyleConstants.setAlignment(this.style, StyleConstants.ALIGN_RIGHT);
        }
        else if(e.getSource() == this.buttonTextAlignJustify) {
            StyleConstants.setAlignment(this.style, StyleConstants.ALIGN_JUSTIFIED);
        }
        else if(e.getSource() == this.buttonTextBold) {
            if(StyleConstants.isBold(this.attributes))
                this.attributes.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.FALSE);
            else
                this.attributes.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.TRUE);
        }
        else if(e.getSource() == this.buttonTextItalic) {
            if(StyleConstants.isItalic(this.attributes))
                this.attributes.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.FALSE);
            else
                this.attributes.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.TRUE);
        }
        else if(e.getSource() == this.buttonTextUnderline) {
            if(StyleConstants.isUnderline(this.attributes))
                this.attributes.addAttribute(StyleConstants.CharacterConstants.Underline, Boolean.FALSE);
            else
                this.attributes.addAttribute(StyleConstants.CharacterConstants.Underline, Boolean.TRUE);
        }
        else if(e.getSource() == this.comboBoxPolice) {
            StyleConstants.setFontFamily(this.style, (String)this.comboBoxPolice.getSelectedItem());
        }
        else if(e.getSource() == this.comboBoxTailleTexte) {
            StyleConstants.setFontSize(this.style, Integer.parseInt((String)this.comboBoxTailleTexte.getSelectedItem()));
        }
 
        this.textTampon = textSelect;
        this.previousPosition = positionStart;
 
 
 
        this.textPaneTexte.setCharacterAttributes(attributes, true);
 
        System.out.println("fin\napres update:");
        for (Enumeration en = this.attributes.getAttributeNames(); en.hasMoreElements() ;) {
            System.out.println(en.nextElement());
        }
 
 
 
    }
Merci d'avance.

cordialement.