Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with ScrollPane

 
Hemanth Reddy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic