Bonjour serait-il possible de créer un Font qui aurait "BOLD" et "LAYOUT_RIGHT_TO_LEFT" ?
Ou une autre solution sans passer par les Fonts ?
Version imprimable
Bonjour serait-il possible de créer un Font qui aurait "BOLD" et "LAYOUT_RIGHT_TO_LEFT" ?
Ou une autre solution sans passer par les Fonts ?
En général avec les fonts, on peut cumuler certains style comme ceci :
Mais la propriété LAYOUT_RIGHT_TO_LEFT ne fait pas partie des styles il me semble.Code:Font font = new Font("Tahoma", Font.BOLD|Font.ITALIC, 11);
Pour cela je pense (en me trompant peut être) qu'il faut jouer dans le paint du composant et user de GlyphVector, un peu comme ceci :
Mais je doute que ce code soit bon... mais peut être pour un début.Code:
1
2
3
4
5
6
7
8 Graphics2D g2d = (Graphics2D) g; FontRenderContext ctxt = g2d.getFontRenderContext(); GlyphVector glyphVector = font.layoutGlyphVector(ctxt, "Salut mon ami".toCharArray(), 0, 10, Font.LAYOUT_RIGHT_TO_LEFT); Rectangle2D logicalBounds=glyphVector.getLogicalBounds(); float tx=(float)(logicalBounds.getX() - 0.5 * logicalBounds.getWidth()); float ty=(float)(8 + logicalBounds.getHeight() + 1.0); Shape labelOutline=glyphVector.getOutline(tx,ty); g2d.fill(labelOutline);