请问Java中怎样把字符旋转90度画到JPanel上? 我记得Graphics中有个类似translate的抽象函数好像其子类的实现是可以实现你的想法的……jdk中的demo中有一个也有你要的功能 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 能在详细一点吗?translate 应该怎么用呢? 从JPanel中继承出一个LabelPanel类,包含angle,text属性。然后重写paintComponent方法: protected void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D)g; g2.setFont(font); FontMetrics fm = g2.getFontMetrics(); int height = fm.getHeight(); int width = fm.stringWidth(text); if(Math.abs(angle-Math.toRadians(90))<0.000001d) { g2.rotate(angle, height/2, height/2); } else if(Math.abs(angle-Math.toRadians(270))<0.000001d) { g2.rotate(angle, width/2, width/2); } else { g2.rotate(0); } if (null!=bgcolor) { g2.setColor(bgcolor); g2.fillRect(0, 0, width, height); } g2.setColor(color); g2.drawString(text, 0, font.getSize()); } 一个复杂一点的简单问题!谢谢! java 400分求操作数据库增删改的DEMO--4 关于反射的问题! 怎么得到系统昨天的时间? 请问,用什么方法读取CSV格式的文件? 大家谁做过这样的程序,能给我一份吗 如果程序中,有两个对象同时调用一个方法会发生什么情况? eclipse插件:openexplorer(直接用资源管理器打开选择文件、文件夹、JAR包)跨平台 再现等待了 关于文件内容替换,达人帮忙啊! 如何对指定的树节点进行着色啊?
然后重写paintComponent方法:
protected void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
g2.setFont(font);
FontMetrics fm = g2.getFontMetrics();
int height = fm.getHeight();
int width = fm.stringWidth(text); if(Math.abs(angle-Math.toRadians(90))<0.000001d) {
g2.rotate(angle, height/2, height/2);
}
else if(Math.abs(angle-Math.toRadians(270))<0.000001d) {
g2.rotate(angle, width/2, width/2);
}
else {
g2.rotate(0);
} if (null!=bgcolor)
{
g2.setColor(bgcolor);
g2.fillRect(0, 0, width, height);
}
g2.setColor(color);
g2.drawString(text, 0, font.getSize());
}