I'm looking to have text display vertically, first letter at the bottom, last letter at the top, within a JLabel. Is this possible?
+2
A:
You can do it by messing with the paint command, sort of like this:
public class JVertLabel extends JComponent{
private String text;
public JVertLabel(String s){
text = s;
}
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
g2d.rotate(Math.toRadians(270.0));
g2d.drawString(text, 0, 0);
}
}
jodonnell
2008-09-18 14:02:56
+2
A:
I found this page: http://www.codeguru.com/java/articles/199.shtml when I needed to do that.
I don't know if you want the letters 'standing' on each other or all rotated on their side.
Arthur Thomas
2008-09-18 14:19:20
Could you put some of the code here that does the job? Just in case the codeguru thing disappears.
Jay R.
2008-09-24 17:34:41
I don't want to copy code from their site.. I don't think that would be right. sorry :(
Arthur Thomas
2008-09-26 18:42:55
A:
Arthur, thank you, that's exactly what I was looking for. When I get a 15 rep, I'll vote you up :)
Clinton
2008-09-18 14:26:56
A:
Another way to show text in a JLabel vertically is to use HTML tags in the text of the JLabel. For example setText("<HTML>H<br>E<br>L<br>L<br>O</HTML>");
will set the text to
H
E
L
L
O
ShawnD
2008-09-22 19:00:33