java - 仅在一侧的圆角边框 java

标签 java swing border

我只需要在组件的一侧上创建一个圆角边框。

此代码创建一个圆角边框:

  new LineBorder(Color.RED, 3, true)

我看过this thread它向您展示了如何创建只能在组件的一侧使用的磨砂边框,但磨砂边框不是圆形的。

是否可以只在一侧有圆角边框?

编辑:

我试过像这样使用复合边框:

    cell.setBorder(BorderFactory.createCompoundBorder(
        new LineBorder(borderColor, 3, true),
        BorderFactory.createMatteBorder(0, 3, 0, 0, Color.black)));

但它不起作用......

最佳答案

你可以覆盖 LineBorder 的方法并在那里绘制所有你需要的 来自 LineBorder 的来源

    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
        Color oldColor = g.getColor();
        int i;

    /// PENDING(klobad) How/should do we support Roundtangles?
        g.setColor(lineColor);
        for(i = 0; i < thickness; i++)  {
        if(!roundedCorners)
                g.drawRect(x+i, y+i, width-i-i-1, height-i-i-1);
        else
SET CLIP HERE TO DRAW ONLY NECESSARY PART
                g.drawRoundRect(x+i, y+i, width-i-i-1, height-i-i-1, thickness, thickness);
        }
        g.setColor(oldColor);
    }

关于java - 仅在一侧的圆角边框 java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7040812/

相关文章:

Python/QT - 我该怎么做才能在一系列小部件之间获得 4 个像素边框?

java - 如何用java代码给系统用户添加密码

java - Swing 常数与组件常数

java - 'synchronized'与ReentrantLock有何关系?

java - JTable 错误 : java. lang.ArrayIndexOutOfBoundsException: 1 >= 0

html - 在点边框中添加中断

java - spring cloud端口号,让选择变得智能

java - 这个 Java 小部件的名称是什么?

java - 将 JButton 放在右下角

html - 文本区域边框颜色没有完全改变