Monday, May 14, 2012

How to add a List of JButtons to a JFrame?

So... I'm making a Jeopardy game, and I'm experimenting with better ways of making and adding the buttons so that it looks better in the source code. So to start off, I have a CategoryClass that takes the parameters of a List of QuestionButtons (basically a JButton), the category name and so on. The only trouble I'm having is adding the buttons to a JPanel. Here's the code:



    public void addCategoryButtons(JPanel pane) {
JLabel head = this.getCategoryHeading();
pane.add(head);
List<QuestionButton> buttons = this.getCategoryButtons();
for (int i = 0; i < buttons.size(); i++) {
pane.add(buttons.get(i).getButton());
}
}


And here's what I get. Note: the "Test" is the name of the category



As you can see, It shows the last Category I add instead of all of them. Any suggestions?





No comments:

Post a Comment