aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes GUI nightmare Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GUI nightmare" Watch "GUI nightmare" New topic
Author

GUI nightmare

Dave Johnson
Ranch Hand

Joined: May 25, 2003
Posts: 111
Here are my 3 classes so far:
BarTill:

ChoicePanel:

SubChoicesPanel:

The first 2 classes are ok (for now). The 3rd class is giving me a lot of trouble. Being honest I can handle layout managers with simple projects, but I am getting into all sorts of problems with this.
The SubChoicesPanel class is supposed to create a GridLayout panel 4 columns wide and the rows are dependant on how many JLabels exist in the array subChoices. So if the user selected Draught Beer in the program the 1st row in the grid would be a JLabel Bitter �2.04 per pint, then a JButton +, then a JButton -, then a JLabel 0. This sequence of components would repeat filling the grid.
When I run the program the code creates a GridLayout that is 2 columns wide even though I constructed a GridLayout 4 columns wide.
Because I'm populating the various components & adding then to my panel using loops this makes it hard for me to spot where I am going wrong.
Please help?
Many thanks, Dave.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

The reason is because the GridLayout puts most of it's effort into meeting the first constraint specified in it. The number of rows that you are specifying by using "subChoices[num].length" is *not* the number of rows that you actually want... it is double the number of rows, because you are storing both the name and the cost as strings in this array.

You can do either one of these things to get the GridLayout to work... specify "subChoices[num].length / 2" as the rows, or just put "0" as the row value. A "0" value as the rows parameter lets the GridLayout know that only thing it should care about is the columns, never mind how many rows are passed to it.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Dave Johnson
Ranch Hand

Joined: May 25, 2003
Posts: 111
I don't know why it was that int j=0; was in the loop. I moved it to the block before and it comes as no suprise the all the JButtons have listeners. Thanks Nathen.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GUI nightmare
 
Similar Threads
Tally will not add up
GUI almost there. Please help!
Some buttons do... Some buttons don't...
JLabel for more than 1 line of text!
I'm stuck!