有没有办法让 jtextfield 的一侧(即右边框线)着色 [英] Is there any way to get one side(i.e., right bordered line) of the jtextfield colored

查看:51
本文介绍了有没有办法让 jtextfield 的一侧(即右边框线)着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我准备了一个摆动框架,在其中放置了两个文本字段.有没有办法让 jtextfield 的一侧(即右边框线)着色?请建议.我检查了很多东西,但找不到.提前致谢.

Hi I prepared one swing frame in which I placed two text fields. Is there any way to get one side(i.e., right bordered line) of the jtextfield colored? Please suggest. I checked many things, but I couldn't find.Thanks in advance.

推荐答案

我会在文本字段中添加一个边框,大致如下:

I would add a Border to the text field, something along the lines of:

Border oldBorder = jTextField.getBorder();
Border redBorder = BorderFactory.createMatteBorder(0, 0, 0, 5, Color.RED);
Border newBorder = BorderFactory.createCompoundBorder(redBorder, oldBorder);
jTextField.setBorder(newBorder);

此方法保留旧边框并将其包裹在红色(部分)边框内.

This approach keeps the old border and wraps it inside your red (partial) border.

这篇关于有没有办法让 jtextfield 的一侧(即右边框线)着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆