I have a panel(JPanel) and it has FlowLayout by default. It has no preferredsize. I have a JScrollPane. So When I am adding buttons to the panel, the buttons are horizontally added. I want that to be added vertically.
panel = new JPanel();
JButton clearButton = new JButton("CLEAR");
panel.add(button);
JScrollPane scroller = new JScrollPane(panel);
scroller.setWheelScrollingEnabled(true);
scroller.setPreferredSize(new Dimension(100, 80));
scroller.setMinimumSize(new Dimension(100, 80));
scroller.setMaximumSize(new Dimension(100, 80));
content.add(scroller, BorderLayout.WEST);
content is the container of the JFrame.
Now if I set a BoxLayout for the panel, then the buttons are left-aligned and I don't want that. So I can't add this code : panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
So can you tell me a process where I can add buttons vertically and also center aligned and after the area is full, then a vertical scrollbar will automatically come.