I have programmed a Swing component requiring scrollbars in the usual way by instantiating the JScrollPane and adding a JTextPane to it.
My program allows the user to add files into the JTextPane which are visually represented by an ImageIcon in a JLabel. The JTextPane is programmed with a flow layout. When I test it by adding icons with a drag and drop gesture from the native system, the icons fill the JTextPane one after the other just as they would with a flow layout from left to right, however when the row of icons reaches the bottom of the window, no scrollbars appear and the icons can be added without errors showing up.
Difficult to know how to help without more details. What have you got on the contents of the JScrollPane? FlowLayout may make it awkward, because it doesn't constrain the size of Components, so the scroll bars may never appear.
I have got a Component call IconCell that has an ImageIcon in the Center Layout, and the text label for the file name in the South Layout. The Icon is the same one that represents the file in Window from whence it came via:
I have used the setPreferredSize() mehod to be the same Dimension regardless of the length of the filename and to accomodate the natural size of the big icon obtained using the above method.
Joined: Oct 13, 2005
Still don't know. Where are you adding the JScrollPane?