'Can you create a default JButton which sets default properties like bounds, border style etc for all buttons that I create later?

I am trying to create a lot of buttons which the number of buttons is set by the user so I dont know how to take the input of the user and create that much variables as the input. And because of that java outputs an error because there is no size the button isnt shown, because the button isnt saved into a variable.

To simplify it: If its possible I am trying to create a default button and use its size and styling for other buttons as well, if I need to change something for a specific button I will just manually add new properties.

If you know a better solution I would gladly hear it and try it.

ArrayList<JButton> arrListOfTask = new ArrayList<>();
arrListOfTask.add(new JButton(task));
// Task is just a String

If I put properties like directly into the new JButton then the button wont be added into the ArrayList. For example:

ArrListOfTask.add(new JButton(task).setBounds(x-pos, y-pos, width, height));
// This doesn't work

If I didn't explain properly please just ask for more explanation and I will do my best to explain.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source