• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help me display array of JButtons properly

 
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic