简体   繁体   English

可以改变 JButton 的形状吗?

[英]Possible to change the shape of JButton?

是否可以将 JButton 的形状从矩形更改为圆形?

I think this might be what you're looking for: 我认为这可能是您要寻找的:

http://java-swing-tips.blogspot.com/2008/11/rounded-corner-jbutton.html http://java-swing-tips.blogspot.com/2008/11/rounded-corner-jbutton.html

It has plenty of code examples, and seems to be what you're looking for. 它具有大量的代码示例,似乎正是您想要的。 Hope this helps! 希望这可以帮助!

Link provided by Sean Cogan is all you need. Sean Cogan 提供的链接就是您所需要的。 If you want it in short ,set an image (rounded or any shape that you want your button should look alike) using setIcon and then on the JButton (button1) set these values -如果您想要简短,请使用setIcon设置图像(圆形或任何您希望按钮看起来相似的形状),然后在 JButton (button1) 上设置这些值 -

button1.setContentAreaFilled(false);
button1.setFocusPainted(false);
button1.setBorderPainted(false);

您还可以在按钮上使用图像。

Well, I found one more useful article in this regard: 好吧,我发现了这方面的另一篇有用的文章:

http://www.dreamincode.net/forums/topic/207123-change-the-shape-of-jbutton/ http://www.dreamincode.net/forums/topic/207123-change-the-shape-of-jbutton/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM