Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

adding JPanel to a JScrollPane  RSS feed

 
Niels Tielenburg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm trying to get a JPanel into a JScrollPane by clicking a button
I have a JScrollPane in a JFrame and when I push a button I'm running the following code:

but when I do that it doesn't show the InvoegPanel()

I've allready got this to work:


but this is whith another frame

anyone that can help me?

 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

We usually discuss that sort of question on the Swing forum, so I shall move this thread.

Are you really using a Listener to add panels to components? Are you using NetBeans as a beginner? Don't use the automatic code generation tools; they simply make learning more difficult. How are you adding the JScrollPane to the Frame?

By the way: Don't call your class "Frame"; there already is a "Frame" class in the java.awt package, and you can cause confusion if you have two classes with the same name.
 
Niels Tielenburg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Netbeans indeed, but I thought that would make it easier, it's just dragging the components and that's all you have to do:P

But I just need to get a frame when I push the button, because I want another frame in the same place when I push another button and I need it to be scrollable bacause the JPanel is to large for my pc screen
 
Rob Camick
Ranch Hand
Posts: 2800
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't add components to a scrollpane. You add components to the viewport of the scrollpane using:

 
Niels Tielenburg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, it worked
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!