I have a panel with a BoxLayout layout and I want this panel to have a scrollbar, so I made a JScrollPane. But when I use JScrollPane, the emptyBorder that I add is not added to my panel
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel , BoxLayout.Y_AXIS));
panel.setOpaque(false);
panel.setBorder(BorderFactory.createEmptyBorder(20, 60, 0, 60));
panel.add(new ToDoPanel());
panel.add(new JEmptyBox(0, 20));
panel.add(new ToDoPanel());
panel.add(new JEmptyBox(0, 20));
panel.add(new ToDoPanel());
panel.add(new JEmptyBox(0, 20));
panel.add(new ToDoPanel());
panel.add(new JEmptyBox(0, 20));
panel.add(new ToDoPanel());
JScrollPane pane = new JScrollPane(panel);
pane.setOpaque(false);
pane.getViewport().setOpaque(false);
pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
pane.getVerticalScrollBar().setUnitIncrement(40);
add(pane, BorderLayout.CENTER);
Without JScrollPage
With JScrollPane