I have a window, containing a frame and JScrollBar. JScrollBar has panel, whose size i want to change at run time if any child component is added with it. Child component size is constant and should not change.
I have Horizontal scrollBar disabled. So if placement of Child Component exceeds panel width, it should go to next row and panel height should change automatically.
Here is code snippet
JScrollPane scrollPane = new JScrollPane();
menuPane = new JPanel();
menuPane.setLayout(new FlowLayout(FlowLayout.CENTER));
scrollPane.setViewportView(menuPane);
MenuTray mtFile = new MenuTray("File"); // MenuTray extends JPanel
menuPane.add(mtFile);
Menu mNew = new Menu((new ImageIcon(MenuScreen.class.getResource("/com/srinar/res/New.png"))), "New"); // Menu extends JLabel
mtFile.add(mNew);
frame.getContentPane().add(scrollPane);