File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem with ScrollPane" Watch "Problem with ScrollPane" New topic

Problem with ScrollPane

Hemanth Reddy

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

Joined: Oct 13, 2005
Posts: 46348
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

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

Joined: May 03, 2008
Posts: 5115

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.
I agree. Here's the link:
subject: Problem with ScrollPane
It's not a secret anymore!