This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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 ?
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?
Joined: Apr 12, 2012
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.