简体   繁体   English

一次样式所有JButton

[英]Styling all JButtons at once

When setting styles for JButton components. JButton组件设置样式时。 Is there a way to set the style for multiple buttons at once if they have the same style or do I need to set it each separately? 如果它们具有相同的样式,是否可以同时设置多个按钮的样式,或者是否需要分别设置每个样式?

With a loop for, you can set the style. 通过循环,您可以设置样式。 Example: 例:

JButton[] button;
for(i=0; i<button.length; i++){
    button[i] = new JButton[];
    String nameButton = "Button" +i;
    button[i].setText(nameButton);
    button[i].setBackground(Color.RED);
} 

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

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