tags:

views:

584

answers:

4

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
+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
Could you put some of the code here that does the job? Just in case the codeguru thing disappears.
Jay R.
I don't want to copy code from their site.. I don't think that would be right. sorry :(
Arthur Thomas
A: 

Arthur, thank you, that's exactly what I was looking for. When I get a 15 rep, I'll vote you up :)

Clinton
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