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.
Version imprimable
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.
Voila, g trouvé une solution que je vous donne
Ceci n'est qu'un brouillon.
Voila ce qu'il faut mettre dans le main:
Et voici la classe VerticalButtonUICode:
1
2
3
4 JButton b = new JButton( "Julien" ); b.setUI(new VerticalButtonUI(false)); frame.getContentPane().add( b );
Code:
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 ); } }