Java Swing JtextField 插入
我正在使用 Netbeans GUI,我想在 jTextField 的开头添加 3 个像素的空间:
我已经尝试在 GUI 中使用 setMargin、setInset 但它没有改变任何东西。
我还有一个问题,为什么右下边框不是圆角的?这是我的代码:
Border roundedBorder = new LineBorder(new Color(210,210,210), 1, true);
researchTextField.setBorder(roundedBorder);
非常感谢,
问候
I am working with Netbeans GUI and I would like to add 3 pixels of space at the beginning of my jTextField :
I have tryied with setMargin, setInset in the GUI but it doesn't change anything.
I have another question, why the bottom right border is not rounded ? here is my code :
Border roundedBorder = new LineBorder(new Color(210,210,210), 1, true);
researchTextField.setBorder(roundedBorder);
thank you very much,
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 setMargin(...) 应该可以。
但是,如果您还使用边框,那么这可能就是问题所在。
尝试使用CompoundBorder,其中内部边框是EmptyBorder(),外部边框是您的其他边框。例如:
阅读 Swing 教程中关于如何使用边框<的部分/a> 了解更多信息和示例。
我不确定为什么你的底部/右侧不是圆形的。在 XP 上使用 Metal LAF 时,右边框(顶部和底部)显示为圆形,但左边框不是圆形的。当我使用 2 或更多的边框大小时,所有角都显示为同样的圆角。
Using
setMargin(...)
should work.However, if you are also using a Border then that may be the problem.
Try using a
CompoundBorder
where the inner border is an EmptyBorder() and the outer border is your other border. For example:Read the section from the Swing tutorial on How to Use Borders for more information and examples.
I'm not sure why your bottom/right is not rounded. Using the Metal LAF on XP the right borders (top and bottom) appear rounded but the left borders are not rounded. When I use a border size of 2 or more all corners appear equally rounded.
setMargin(Inset myInset)
为我工作:setMargin(Inset myInset)
worked for me: