• Post Reply Bookmark Topic Watch Topic
  • New Topic

Scrollbars

 
Rocky Summers
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
how do i add a scrollbar in a Container?
i have this:

so how do i add an automatic scrollbar so that when the user resizes the screen, it will automatically create the scrollbar so we can see things that are covered.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't say if you are using AWT or Swing... if you are using Swing, add everything to a JPanel, add the JPanel to a JScrollPane, and then add the JScrollPane to the content pane. If you are using AWT, add everything to a Panel, add the Panel to a ScrollPane, and add the ScrollPane to the Frame.

Here's the section on JScrollPane in the Swing Tutorial.
 
Rocky Summers
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you nate
im going to try that!
 
Rocky Summers
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you say, 'add everything to the frame' does that mean adding it to my container? sorry im fairly new at this. thank you
 
Rocky Summers
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried what nate suggested but the scrollbar still won't show up... (btw im using swing)
here's how i did it.

and in my Login1_Layout1 class....

Any suggestions...?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try putting the show() after the setSize() in the JFrame... trying to show the frame before it has a legitimate size causes all kinds of problems. Things aren't calculated correctly.
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
show() is deprecated, instead you should use setVisible(boolean b), and I think you may need to call pack() prior to it.
 
Rocky Summers
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you!!! awesome.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!