java怎么做好看的边框,如何在Java中创建这样的边框?

I've been trying to replicate this border for hours without success:

x9pqM.png

Any idea on how to do this?

解决方案

This is Borders from SwingX (some older version), but I can't found this older repository right now

by using this Image (cuold be colorized with un_belivable Colors and required another classes Painter and???)

jViJ7.png

private static class RoundedBorder implements Border {

private static BufferedImage img;

static {

try {

img = ImageIO.read(RoundedBorder.class.getResource("resources/border.png"));

} catch (Exception e) {

}

}

private static final Insets SPACE_INSETS = new Insets(5, 5, 5, 5);

private static final Insets INSETS = new Insets(SPACE_INSETS.top + 10, SPACE_INSETS.left + 10, SPACE_INSETS.bottom + 10, SPACE_INSETS.right + 10);

@Override

public Insets getBorderInsets(Component c) {

return INSETS;

}

@Override

public boolean isBorderOpaque() {

return false;

}

@Override

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

Rectangle b = new Rectangle(x + SPACE_INSETS.left, y + SPACE_INSETS.top, width - (SPACE_INSETS.left + SPACE_INSETS.right + 1),

height - (SPACE_INSETS.top + SPACE_INSETS.bottom + 1));//top

g.drawImage(img, b.x, b.y, b.x + 10, b.y + 10, 0, 0, 10, 10, null);

g.drawImage(img, b.x + 10, b.y, b.x + b.width - 10, b.y + 10, 11, 0, 12, 10, null);

g.drawImage(img, b.x + b.width - 10, b.y, b.x + b.width, b.y + 10, 22, 0, 32, 10, null);// bottom

g.drawImage(img, b.x, b.y + b.height - 10, b.x + 10, b.y + b.height, 0, 22, 10, 32, null);

g.drawImage(img, b.x + 10, b.y + b.height - 10, b.x + b.width - 10, b.y + b.height, 11, 22, 12, 32, null);

g.drawImage(img, b.x + b.width - 10, b.y + b.height - 10, b.x + b.width, b.y + b.height, 22, 22, 32, 32, null);// left

g.drawImage(img, b.x, b.y + 10, b.x + 10, b.y + b.height - 10, 0, 11, 10, 12, null);// right

g.drawImage(img, b.x + b.width - 10, b.y + 10, b.x + b.width, b.y + b.height - 10, 22, 11, 32, 12, null);// fill

g.drawImage(img, b.x + 10, b.y + 10, b.x + b.width - 10, b.y + b.height - 10, 15, 15, 16, 16, null);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值