JButton 美化(圆角矩形立体效果加鼠标响应)Demo.rar

时间:2023-05-03 04:33:12
【文件属性】:

文件名称:JButton 美化(圆角矩形立体效果加鼠标响应)Demo.rar

文件大小:24KB

文件格式:RAR

更新时间:2023-05-03 04:33:12

java

主要代码: @Override public void paintIcon(Component cmp, Graphics g, int x, int y) { Color lowerColor = new Color(235,255,235); Color highColor = new Color(81,184,77); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); // 画一个渐变圆角矩形 RoundRectangle2D.Float r2d=new RoundRectangle2D.Float(0, 0, btnWidth - 1, btnHeight - 1, 20, 20); Shape clip=g2d.getClip(); g2d.clip(r2d); GradientPaint paint = new GradientPaint(0.0F,0.0F,lowerColor,0.0F,btnHeight,highColor,true); g2d.setPaint(paint); g2d.fillRect(0,0,btnWidth,btnHeight); g2d.setClip(clip); // 画一个黑色边框 paint = new GradientPaint(0,0,new Color(0,0,0), 0,btnHeight-1,new Color(100,100,100)); g2d.setPaint(paint); g2d.drawRoundRect(0,0,btnWidth-1,btnHeight-1,20,20); // 画一个白色边框 paint=new GradientPaint(0,1,new Color(0,0,0,50),0,btnHeight-3,new Color(255,255,255,100)); g2d.setPaint(paint); g2d.drawRoundRect(1,1,btnWidth-3,btnHeight-3,18,18); FontMetrics fm = g2d.getFontMetrics(boldFont); int textWidth = fm.stringWidth(btnText); int textAscent = fm.getAscent(); g2d.setColor(hoverColor); g2d.setFont(boldFont); g2d.drawString(btnText, (btnWidth - textWidth) / 2, (btnHeight + textAscent) / 2 - 2); }


【文件预览】:
Demo_App
----src()
--------Btn2D.java(593B)
--------MainClass.java(260B)
--------TextFieldBorder.java(1KB)
--------Btn2dEx.java(7KB)
--------BtnUi.java(1KB)
--------TextFieldEx.java(2KB)
--------BtnEx.java(4KB)
----bin()
--------BtnEx$5.class(715B)
--------Btn2dEx$5.class(727B)
--------BtnEx$4.class(1KB)
--------Btn2dEx$2.class(3KB)
--------Btn2dEx$4.class(1KB)
--------TextFieldEx.class(1KB)
--------BtnEx.class(2KB)
--------Btn2D.class(1023B)
--------MainClass.class(398B)
--------TextFieldBorder.class(2KB)
--------TextFieldEx$1.class(1KB)
--------Btn2dEx.class(3KB)
--------BtnEx$2.class(2KB)
--------BtnEx$3.class(2KB)
--------BtnEx$1.class(2KB)
--------BtnUi.class(2KB)
--------Btn2dEx$1.class(3KB)
--------Btn2dEx$3.class(3KB)
----.classpath(301B)
----.settings()
--------org.eclipse.jdt.core.prefs(598B)
----.project(384B)

网友评论