In netbeans I added a scroll pane + bar inside one of my JPanels. When I drag enough items into the JPanel, the size of the JPanel increases in netbeans. How do I get it so that it stays at a fixed size, so I can use the scroll bar?

Recommended Answers

All 4 Replies

Little silly question. Did you try setMaximumSize(Dimension maximumSize) on JPanel?

I tried setDefaultSize. I'm trying to learn how to use the built in netbeans buttons, such as the ones under properties, although I should have considered that it'd "listen" to me if I set the maximum size! Haha. Thanks.

I've tried a variety of things, nothing works. There is probably something easy and obvious I'm missing. I'm just trying to make it so that once my items inside the JPanel take up too much room, I can scroll vertically to see them. I can do this hard coded - I've succeeded in doing so before anyway - but I can't get netbeans to do it. If anyone knows how to make it so you can scroll in a JPanel in netbeans, please give me some tips.

I figured it out. Two tips for people who run into problems like this in the future:

1. Your scroll pane should be added first in netbeans. Then the JPanel or whatever should be added to it. (Think about it like this - in the how to use scroll panes java tutorial, the component that you want to make scrollable (in this case, my JPanel), is the argument to the JScrollPane constructor).
2. Setting the size of the JPanel or whatever component it is might result in some of the information not being displayable. When I set the size of the JPanel to null, I think this allowed the JScrollPane to determine the JPanel's size.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.