Note some problems with your code:
JPanel listObject = new JPanel(null);
You're adding this to a JScrollPane and note that JScrollPanes don't handle null
layout-using viewport views well at all. It in fact can completely mess up the scrollpane's ability to scroll.
listObject.setBounds(0, 350, 300, 100);
By calling setBounds(...)
you're in effect saying try to put this component at the [0, 350] position of the container that holds it and size it to [300, 100]. Note that the container that you're adding it to is the JScrollPane's viewport. So if the viewport follows this request, and since you're trying to make your JScrollPane and its viewport have a width of 270 with this code here:
scroll.setBounds(0, 375, 270, 100);
You're in effect asking the JScrollPane to add a JPanel way off to the right beyond the bounds of the JScrollPane itself. Ignoring that the viewport is likely not even using a null layout, this really makes little sense.
You will want to get rid of the setBounds(...)
business to start with. JScrollPanes use their own layouts, and so there is no need or good effect by trying to set the bounds of a component being added to it. Instead consider overriding the JPanel's getPreferredSize. Also, a component held by a JScrollPane should not use a null
layout as this will usually prevent the JScrollPane from working correctly, from knowing how to scroll the container.
The bottom line here is that you will want to avoid null
layouts in general as they lead to the creation of rigid GUIs that are very difficult to enhance or debug, that may look OK on one platform but will definitely look bad on all other platforms or screen resolutions. It's a newbie trap to think that null layout is the way to go, one that you'll quickly learn to avoid the more experience you gain.
If you're still stuck after reading the answers, please consider creating and posting your minimal example program, a small compilable and runnable program that shows for us your problem.