简体   繁体   English

制作所有带圆角的JButton的最佳方法

[英]Best way to make all JButtons with round corners

I believe it's a popular topic but i still want to ask an advise. 我相信这是一个热门话题,但我还是想问一个建议。

I want to make all of JButtons from Swing with rounded corners, and there seem to be at least 3 ways to do so. 我想用Swing制作带有圆角的所有JButton,并且似乎至少有3种方法可以做到这一点。

1)I can create my own Look and feel based on synth L&F, where all buttons will be shown with rounded borders, but it seems to be like shooting the flies with cannon so... 1)我可以基于合成器L&F创建我自己的外观和感觉,其中所有按钮都将显示为圆形边框,但它似乎就像用大炮射击苍蝇所以......

2)I thought of extending JButton class and making all buttons with rounded corners, it's very easy, but, although i don't have any memory restrictions i think it is still too much to load a whole new class in Java just for this borders... And as i've seen it, there are no interfaces that i can use instead of extending JButton. 2)我想扩展JButton类并使所有按钮都有圆角,这很容易,但是,尽管我没有任何内存限制,我认为用Java加载一个全新的Java类仍然太多了...正如我所见,没有可以使用的接口而不是扩展JButton。

3)And for the last solution i can just iterate through all of my JButton components after the GUI was created and call something like a setBorder(new MyOwnRoundedBorder(int radius)); 3)对于最后的解决方案,我可以在创建GUI之后迭代我的所有JButton组件并调用类似setBorder(new MyOwnRoundedBorder(int radius)); for each of them, but it doesn't seem very code frienldy to me. 对于他们每个人来说,但对我来说似乎并不是很好的代码。

Please help me find my way through this possible prejudicies. 请帮助我找到可能的偏见。

Thank you in advance. 先感谢您。

2) is no good Idea, as soon as you reuse existing components (ie file open dialogues) the original JButton is used. 2)没有好主意,只要重用现有组件(即文件打开对话框),就会使用原始JButton。

3) same issue + maintenance problems 3)同样的问题+维护问题

It seems you have to create your own look&feel 看来你必须创造自己的外观和感觉

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

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