PDA

View Full Version : بک گراند jlabel با graphics و دیده نشدن متن داخلش



hossein71
دوشنبه 03 مهر 1391, 11:33 صبح
برای رنگ بک گراند jlabel کد زیر رو نوشتم ولی نمیدونم چرا متن داخلش دیده نمیشه.

public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D)g.create();
int w = getWidth();
int h = getHeight();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASI NG, RenderingHints.VALUE_ANTIALIAS_ON);

g2d.setPaint( new GradientPaint( 0, 0, new Color(220,240,240), 10, 180, new Color(100,130,130)));
g2d.fillRoundRect(2, 2, w-4, h-4, arcs.width, arcs.height);
}

spiderman200700
سه شنبه 04 مهر 1391, 00:52 صبح
سلام. اینطوری بنویس:
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g.create();
int w = getWidth();
int h = getHeight();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASI NG, RenderingHints.VALUE_ANTIALIAS_ON);

g2d.setPaint( new GradientPaint( 0, 0, new Color(220,240,240), 10, 180, new Color(100,130,130)));
g2d.fillRoundRect(2, 2, w-4, h-4, arcs.width, arcs.height);
}

موفق باشی.

hossein71
شنبه 08 مهر 1391, 18:46 عصر
ممنون spiderman200700 (http://barnamenevis.org/member.php?133001-spiderman200700)
اگر حالا paintborder داشته باشیم باید چیکار کنم؟
از super.paintborder استفاده کردم فایده نداشت و متن ها نمایش داده نمیشد.

public class BorderEdit extends AbstractBorder{
int r,top,left,bottom,right;
Color Crect,Cbor,Gradient1,Gradient2;
int x1,x2,y1,y2;
boolean gra;
public BorderEdit(boolean gra, int x1, int x2, Color Gradient1, int y1, int y2, Color Gradient2, int r, Color Crect, Color Cbor, int top, int left, int bottom, int right){
this.r=r; this.Crect=Crect; this.Cbor=Cbor; this.top=top; this.left=left; this.bottom=bottom; this.right=right; this.gra=gra;
this.Gradient1=Gradient1; this.Gradient2=Gradient2;
this.x1=x1; this.x2=x2; this.y1=y1; this.y2=y2;
}
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Graphics2D g2 = (Graphics2D)g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASIN G, RenderingHints.VALUE_ANTIALIAS_ON);
RoundRectangle2D round = new RoundRectangle2D.Float(x, y, width-1, height-1, r, r);

g2.setColor(Crect);
Area corner = new Area(new Rectangle2D.Float(x, y, width, height));
corner.subtract(new Area(round));
g2.fill(corner);

g2.setColor(Cbor);
g2.draw(round);

if(gra==true){
g2.setPaint( new GradientPaint( x1, x2, Gradient1, y1, y2, Gradient2));
g2.fillRoundRect(2, 2, width-4, height-4, r, r);
}
g2.dispose();
}
}