Orienter le texte d'un label comme on veut

Résolu
kobee12 Messages postés 153 Date d'inscription dimanche 26 janvier 2003 Statut Membre Dernière intervention 31 octobre 2006 - 20 juin 2005 à 13:48
kobee12 Messages postés 153 Date d'inscription dimanche 26 janvier 2003 Statut Membre Dernière intervention 31 octobre 2006 - 21 juin 2005 à 10:45
Bonjour à tous.

j'aimerais créer un label orienté à la vertical(90 °). Ainsi j'aurais du texte écris à la verticale et non à l'horizontale comme ci dessous :

Seulement je ne sais s'il existe une fonction pour cela.
Est ce que quelqu'un peut m'aider.
Merci

Kobee12

5 réponses

kobee12 Messages postés 153 Date d'inscription dimanche 26 janvier 2003 Statut Membre Dernière intervention 31 octobre 2006 1
21 juin 2005 à 10:45
Bon j'ai trouvé.
J'ai trouvé un code sur le net que j'ai un peu modifié.
Voici ma classe :

import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;


public class VTextPanel extends JPanel {
AffineTransform at = new AffineTransform();
int w, h;
String text;
public VTextPanel(String text) {
this.text = text;
this.setBackground(new Color(194, 194, 194));
}


public void setTrans() {
at.rotate(Math.toRadians(-90));
}


public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
at.setToIdentity();
setTrans();
g2.transform(at);
g2.drawString(text, -((getSize().height)-(((getSize().height)-(text.length()*5))/2)),
((getSize().width) / 2));
}
}

Et on fait appel comme ceci :
VTextPanel vtp = new VTextPanel("Texte à la verticale");
jPanelTextDate.add(vtp, java.awt.BorderLayout.CENTER);

Si on veut que le texte à afficher soit penché de l'autre sens mettre :
at.rotate(Math.toRadians(90));
et
g2.drawString(text, ((getSize().height)-(((getSize().height)-(text.length()*5))/2)),
-((getSize().width) / 2));

Vous trouverez d'autres infos sur le site :
http://forum.java.sun.com/thread.jspa?threadID=242381&messageID=3510402

Voila

@ + Kobee12
3
safisoft Messages postés 489 Date d'inscription vendredi 30 janvier 2004 Statut Membre Dernière intervention 13 mai 2009 6
20 juin 2005 à 15:19
BLATEER
0
safisoft Messages postés 489 Date d'inscription vendredi 30 janvier 2004 Statut Membre Dernière intervention 13 mai 2009 6
20 juin 2005 à 15:23
BLATEER
0
safisoft Messages postés 489 Date d'inscription vendredi 30 janvier 2004 Statut Membre Dernière intervention 13 mai 2009 6
20 juin 2005 à 15:24
je sé qu'on pe utiliser un
ComponentOrientation pour fixer l'orientation de l'insertion des compnents ds un
container mé je sé pas si ca sera util ds ton cas! alors c'est à toi defaire une
recherche sur les ComponentOrientation, .setComponentOrientation(......) et
applyComponentOrientation(.....)
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
safisoft Messages postés 489 Date d'inscription vendredi 30 janvier 2004 Statut Membre Dernière intervention 13 mai 2009 6
20 juin 2005 à 15:25
ya un problème ce forum avec internet explorer (j'ai pu enregistrer q'avec firefox!)
0
Rejoignez-nous