IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants Java Discussion :

Orientation texte dans un bouton


Sujet :

Composants Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 5
    Par défaut Orientation texte dans un bouton
    Bonjour, j'aimerai faire un bouton avec le texte orienté de bas en haut (et avec les lettres tournées).

    Pouvez-vous m'aider??

    Merci.

  2. #2
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 5
    Par défaut
    Voila, g trouvé une solution que je vous donne
    Ceci n'est qu'un brouillon.

    Voila ce qu'il faut mettre dans le main:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    		JButton b = new JButton( "Julien" );
    		b.setUI(new VerticalButtonUI(false));
    		frame.getContentPane().add( b );
    Et voici la classe VerticalButtonUI
    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
     
    class VerticalButtonUI extends BasicButtonUI
    {
    	protected boolean clockwise;
    	VerticalButtonUI( boolean clockwise )
    	{
    		super();
    		this.clockwise = clockwise;
    	}
     
     
        public Dimension getPreferredSize(JComponent c) 
        {
        	Dimension dim = super.getPreferredSize(c);
        	return new Dimension( dim.height, dim.width );
        }	
     
        private static Rectangle paintIconR = new Rectangle();
        private static Rectangle paintTextR = new Rectangle();
        private static Rectangle paintViewR = new Rectangle();
        private static Insets paintViewInsets = new Insets(0, 0, 0, 0);
     
    	public void paint(Graphics g, JComponent c) 
        {
    		JButton button = (JButton)c;
            String text = button.getText();
            Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();
     
            if ((icon == null) && (text == null)) {
                return;
            }
     
            FontMetrics fm = g.getFontMetrics();
            paintViewInsets = c.getInsets(paintViewInsets);
     
            paintViewR.x = paintViewInsets.left;
            paintViewR.y = paintViewInsets.top;
     
        	// Use inverted height & width
            paintViewR.height = c.getWidth() - (paintViewInsets.left + paintViewInsets.right);
            paintViewR.width = c.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);
     
            paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
            paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;
     
        	Graphics2D g2 = (Graphics2D) g;
        	AffineTransform tr = g2.getTransform();
        	if( clockwise )
        	{
    	    	g2.rotate( Math.PI / 2 ); 
        		g2.translate( 0, - c.getWidth() );
        	}
        	else
        	{
    	    	g2.rotate( - Math.PI / 2 ); 
        		g2.translate( - c.getHeight(), 0 );
        	}
     
        	if (icon != null) {
                icon.paintIcon(c, g, paintIconR.x, paintIconR.y);
            }
     
            if (text != null) {
                int textX = paintTextR.x;
                int textY = paintTextR.y + fm.getAscent();
     
                if (button.isEnabled()) {
                	paintText(g,c,new Rectangle(paintViewR.x,paintViewR.y,textX,textY),text);
                }
                else {
                	paintText(g,c,new Rectangle(paintViewR.x,paintViewR.y,textX,textY),text);
                }
            }
     
        	g2.setTransform( tr );
       }
    }

Discussions similaires

  1. Zend_form : Intégrer un champ text dans un bouton radio
    Par Devil Shark dans le forum Zend_Form
    Réponses: 2
    Dernier message: 22/10/2008, 17h45
  2. Police de texte dans les boutons
    Par adelsunwind dans le forum IHM
    Réponses: 2
    Dernier message: 20/10/2008, 20h29
  3. Modification d'un texte dans un bouton
    Par atlantis dans le forum ActionScript 3
    Réponses: 3
    Dernier message: 01/04/2008, 14h05
  4. Faire tenir le texte dans un bouton
    Par francoisch dans le forum Balisage (X)HTML et validation W3C
    Réponses: 3
    Dernier message: 04/02/2008, 10h18
  5. [MFC] changement de texte dans un bouton
    Par benjiprog dans le forum MFC
    Réponses: 16
    Dernier message: 12/06/2006, 20h48

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo