Search code examples
javaarraysswingjbuttonjform-designer

Can we store JButtons in an array?


I am trying to make a small application in Java Swing using JFrame form. I added buttons from palette to panel in specific positions and now want to add these buttons to an array but I don't know the data type used for array that holds these designed buttons. I searched for it but didn't find anything related to my problem. I am new to coding and have very limited knowledge about Java - any help will be greatly appreciated.


Solution

  • I you want to have a flexible list of buttons, just declare a List of JButton.

    List<JButton> listOfButton = new ArrayList<>();