This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Help me display array of JButtons properly Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Help me display array of JButtons properly" Watch "Help me display array of JButtons properly" New topic
Author

Help me display array of JButtons properly

Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 571

Hi all...

Im new to swing and I have a 2d array of JButtons...I'm trying to loop through the array and add them to the container but I dont understand how the layout managers work.So my 20x20 grid is being displayed something like 26x11...Could anyone provide a quick fix for the following code?



===>SCJP 1.5(72%)<===
==>SCWCD1.5(76%)<===
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

That's not the code that is giving problems. I mostly copied it, using JButtons directly instead of Tiles (and btw, two cannot be a JPanel).
I get a nice 20x20 grid.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 571

Oh maybe 2 is a JFrame.Anyway will try to use pack() and setLocationRelativeTo(Null).What I am trying to do is to have 3 rows(each with a textfield)and beneath these 3 rows I want the 20x20 grid.What I have done at the moment is to use a flowlayout,and after the textfields have been added,I use a gridLayout....Also,I had set the size of the JFrame..maybe this would cause the problem?For some reason I couldnt use Jbuttons...the text on the Jbuttons weren't displaying and any images that I used as an icon became too distorted...so I switched to regular buttons...
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Help me display array of JButtons properly
 
Similar Threads
One central controller and 4 compas buttons
Multiple mouselisteners
2D inconsistencies
Tile constraints
Help with Jbuttons JText Lotto