import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class myFrame extends JFrame
{
public myFrame()
{
setSize(400,400);
setTitle("vivan is beautiful");

getContentPane().add(new JLabel("<html>垂<br>直<br>显<br>示</html>"),BorderLayout.NORTH);
//setUndecorated(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{System.exit(0);}
});

}

public static void main(String[] args)
{
myFrame myframe=new myFrame();
myframe.show();
}
}

解决方案 »

  1.   

    you can create an ImageIcon with the string
    public static ImageIcon createVerticalTextIcon(String name, int widthp,int heightp)
    {
    int width = widthp;
    int height = heightp;
    BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = (Graphics2D)bi.getGraphics();
    Color c= new Color(0, 0, 0, 0);
    g2.setColor(c);
    g2.fill(new Rectangle(bi.getWidth(), bi.getHeight()));
    g2.setColor(Color.black);
    //g2.rotate((-0.5)*Math.PI, width/2, height/2);
    g2.rotate((0.5)*Math.PI, width/2, height/2);
    Font serifFont = new Font("Serif", Font.PLAIN, 18);
    AttributedString as = new AttributedString(name);
    as.addAttribute(TextAttribute.FONT, serifFont);
    as.addAttribute(TextAttribute.FOREGROUND, Color.red);
    g2.drawString(as.getIterator(), width/2,height/2);
    // g2.drawString(as.getIterator(), -width/2,-height/4);
    Image image = (Image)bi;
    ImageIcon icon = new ImageIcon(image);
    return icon;
    }
      

  2.   

    把JTextArea改装成JLabel( 这个应该会吧,用UIManager) ,然后输入“垂\n直\n显\n示\n”