继承awt.Label,重载paint()函数为什么不能实现自定义绘画? 用paintComponent()方法,最后再调用updateUI()试一下,不行就自己写个UI。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 抱歉,paintComponent()和updateUI()都是swing的:) sorry, paintComopnent()是Container的。但是对Label仍然不起作用的。 g.drawRect(1, 1, this.getWidth()-1, this.getHeight()-1);看看能出来不能 使用drawRect(x,y,width,height)画出的框大小应该是(width+1,height+1)所以画框的代码应改为public void paint(Graphics g) { super.paint(g); g.setColor(this.getBackground()); g.fillRect(0, 0, this.getWidth(), this.getHeight()); g.setColor(this.getForeground()); g.drawRect(0, 0, this.getWidth()-1, this..getHeight()-1);}另外,圆角框线应该使用drawRoundRect方法。 补充:右下角的坐标是(x+width+1,y+height+1);ksxy (空山新雨)的代码画到了Label的外面,所以看不到。 cpu的说法没错,但是……起码应该看到左上的线的。我最后用panel解决的方法如下: /** * Override this method to implement customized painting. * @param g the Graphics. */ public void paint(Graphics g) { g.setColor(borderColor); g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1); g.drawString(" " + tipString + " ", 0, this.getHeight() - 4); }我觉得先前的代码起码应该看到点东东,问题是什么也看不到啊。 呵呵,你把getWidth()和getHeight()的值打出来看看,搞不好都是0 public void paint(Graphics g) { super.paint(g); if(isVisible());//加这样一句试试. g.setColor(this.getBackground()); g.fillRect(0, 0, this.getWidth(), this.getHeight()); g.setColor(this.getForeground()); g.drawRect(0, 0, this.getWidth()-1, this..getHeight()-1);} 补充一下.你画的都给你画了,但是.画的时候你的界面还没显示出来.如果你改变一下label的大小是不是就显示出来啦. 有关jdk的问题 java中如何连接数据库sql server 2000 如何把.java程序变成.exe可执行文件? 如何用java调用windows的dll,例如msimg 急求:Jcreator 显示中文问题 请教如何入门 jbuilder6用了几天后,再起动时出现unknown license file format,如何解决 poolman的使用 请问高手们,如何用JAVA实现ftp协议? 初学java 的弱智问题! 关于jfc的使用? java在什么网址有详细的学习材料?jbuild什么地方可以下载?怎么安装?分数随答案马上给出!
看看能出来不能
所以画框的代码应改为
public void paint(Graphics g) {
super.paint(g);
g.setColor(this.getBackground());
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.setColor(this.getForeground());
g.drawRect(0, 0, this.getWidth()-1, this..getHeight()-1);
}
另外,圆角框线应该使用drawRoundRect方法。
右下角的坐标是(x+width+1,y+height+1);ksxy (空山新雨)的代码画
到了Label的外面,所以看不到。
* Override this method to implement customized painting.
* @param g the Graphics.
*/
public void paint(Graphics g) {
g.setColor(borderColor);
g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1);
g.drawString(" " + tipString + " ", 0, this.getHeight() - 4);
}我觉得先前的代码起码应该看到点东东,问题是什么也看不到啊。
super.paint(g);
if(isVisible());//加这样一句试试.
g.setColor(this.getBackground());
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.setColor(this.getForeground());
g.drawRect(0, 0, this.getWidth()-1, this..getHeight()-1);
}
如果你改变一下label的大小是不是就显示出来啦.