• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to display ScrollPane when added to a Panel  RSS feed

 
sharath kv
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
When I add a ScrollPane directly to a container,using the getContentPane().add(sp),where sp is the ScrollPane, the ScrollPane is visible. But when I add the ScrollPane onto a Panel and then add that panel to a container,I the ScrollPane is not visible.
 
Eugene Ho
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post some code
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because the content pane uses BorderLayout and you are adding it to the center, the scrollpane takes up all available space. JPanel by default uses FlowLayout, which displays components as they are added according to their preferred size. An empty scrollpane has no preferred size, so it's there, it just has a size of 0, so you can't see it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!