error upon assigning Layout: BoxLayout can’t be shared

Your problem is that you’re creating a BoxLayout for a JFrame (this), but setting it as the layout for a JPanel (getContentPane()). Try:

getContentPane().setLayout(
    new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS)
);

Leave a Comment