0

Trying to have 2 panels in a frame, one small one at the top and one filling up the rest of the frame. This code returns a "BoxLayout can't be shared" error though.

        JFrame frame = new JFrame("Clients");
        frame.setSize(1000,900);

        JPanel sorters = new JPanel();
        sorters.setSize(1000, 100);
        frame.getContentPane().add(sorters);

        JPanel rowPane = new JPanel();
        JScrollPane scrPane = new JScrollPane(rowPane, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        scrPane.setSize(1000, 800);
        frame.getContentPane().add(scrPane);

        frame.getContentPane().setLayout(new BoxLayout(frame, BoxLayout.Y_AXIS));
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Skirsch
  • 19
  • 8
  • Please search before asking. A simple search on [BoxLayout can't be shared](https://www.google.com/search?q=java+boxlayout+can%27t+be+shared) brings any and all the links that you need. – Hovercraft Full Of Eels Aug 02 '18 at 18:18

1 Answers1

1

A BoxLayout must have as first parameter the actual container it is applied to, in your case the container is the contentPane of the frame :

frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
Arnaud
  • 17,229
  • 3
  • 31
  • 44