Salut !
Voila j'ai un JTextPane auquel j'ai associé un styled document.
J'insère du texte au fur et à mesure et suivant le texte, le style n'est pas le même (rouge, gras, italique...).
J'aimerai jouer sur l'alignement du texte mais je n'y arrive pas.
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
 
private void initDocument() {
		// Initialize some styles.
		Style def = StyleContext.getDefaultStyleContext().getStyle(
				StyleContext.DEFAULT_STYLE);
 
		Style regular = doc.addStyle("normal", def);
		StyleConstants.setFontFamily(def, "Courier New");
 
		Style s = doc.addStyle("--", regular);// error
		StyleConstants.setForeground(s, new Color(250, 0, 0));
 
		s = doc.addStyle("##", regular);// break
		StyleConstants.setForeground(s, new Color(0, 64, 128));
 
		s = doc.addStyle("**", regular);// conversion
		StyleConstants.setForeground(s, new Color(120, 64, 0));
 
		s = doc.addStyle("$$", regular);// parsing
		StyleConstants.setForeground(s, new Color(0, 128, 128));
 
		s = doc.addStyle("++", regular);// ok
		StyleConstants.setForeground(s, new Color(0, 128, 0));
 
		s = doc.addStyle("info", regular);// information
		StyleConstants.setAlignment(s, StyleConstants.ALIGN_CENTER);
		StyleConstants.setForeground(s, new Color(170, 55, 0));
	}
Je voudrais que seulement le texte associé au style "info" soit centré ? comment puis-je procéder ?
Merki !
+++
Ju