-1

Is there anyway to design multiple buttons at once? I have 9 buttons and I don't wanna design it 1 by 1. Is there anyway to do this? I am good even the can be the same. And also what I wanna do is, in my JPanel, is there anyway to add multiple buttons at once? like panel.add(b1,b2,b3,...)

I tried:

for (int i = 0; i < 9; i++) {
JButton btn = null;
switch (i) {
case 0:
btn = b1;
break;
case 1:
btn = b2;
}
//And btn is up to b9 and i is up to 8
btn.setBackground(Color.black);
btn.setBorderPainted(false);

}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
AdolfJames Urian
  • 97
  • 1
  • 1
  • 9

1 Answers1

0

As per the document

https://docs.oracle.com/javase/7/docs/api/javax/swing/JPanel.html

There is no such method available

if you want such method, then you need to create a custom class extending JPanel

Dickens A S
  • 3,824
  • 2
  • 22
  • 45