This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Problem with ScrollPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem with ScrollPane" Watch "Problem with ScrollPane" New topic
Author

Problem with ScrollPane

Hemanth Reddy
Greenhorn

Joined: Apr 12, 2012
Posts: 8
I am creating an application using frame. Based on the number of words in a string array it should generate buttons. All this is fine, except when the buttons keep getting generated some of them aren't shown as it goes more than the screen size. I tried implementing a scollpane but it didn't work (No compilation errors. The scrollbar doesn't appear). Can somebody help me out with this. Is there any better way to do this ?


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38087
    
  22
I shall move this to our GUIs forum.

Why have you got an array of buttons? You are not using the array. You can iterate through chars because chars are numbers. So you can iterate from 'a' to 'z', and not mess around with arrays or magic numbers like 26. That way you can create your twenty-six buttons.
Where are you adding the buttons? Are you adding them all to the frame where they will go to the centre by default? Are you then adding the scroll pane on top of them?

I think you need to learn about layouts; you probably want a grid layout as the simplest.
And why on earth are you using heavyweight AWT components, rather than Swing?
Hemanth Reddy
Greenhorn

Joined: Apr 12, 2012
Posts: 8
I really don't know how to use swings as i just started off learning java. I used a borderlayout to avoid the centering of elements. This is just an experiment. It doesn't matter about the 26 chars or arrays (I just needed the buttons to overshoot the frame size) . I just wanted to know how to implement a scrollpane.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Hemanth Reddy wrote:I really don't know how to use swings

SwingIsAProperNoun <-- link

You really need to go through some tutorials. You'll find one linked from the API for JScrollPane and you can follow the links on that page to find the others you need.


luck, db
There are no new questions, but there may be new answers.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem with ScrollPane
 
Similar Threads
Text canvas vertical scroll
How to display toolbars like forte4java
JFrame won't repaint...
Horizontal Scrollbar
How to handle events in java