• 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

two grids next to each other

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I've one grid on the screen.

my question is: how can I get two grids next to each other on the same screen?

can someone help me?

thanks in advance

 
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll probably need to make the frame wider to accommodate second grid.
 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you know the pixel dimensions of a "Grid" in advance, you'd probably want to set the preferred and minimum sizes for Grid inside your Grid constructor.
 
wesley johnsen
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it is possible that there is a white space between the grids?
 
wesley johnsen
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for example 3px space?
 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
               JFrame window = new JFrame();
               window.setSize(840, 560);
               window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

               Grid grid1 = new Grid();
               window.add(grid1);
               grid1.fillCell(0, 0);
               grid1.fillCell(79, 0);
               grid1.fillCell(0, 49);
               grid1.fillCell(79, 49);
               grid1.fillCell(39, 24);

               JPanel space = new JPanel();
               space.setSize(3,height);
               window.add(space);

               Grid grid2 = new Grid();
               window.add(grid2);
               grid2.fillCell(0, 0);
               grid2.fillCell(79, 0);
               grid2.fillCell(0, 49);
               grid2.fillCell(79, 49);
               grid2.fillCell(39, 24);

               window.setVisible(true);
 
wesley johnsen
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get no two grids and no space.

Can someone help me?
This is the code:
 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Needed to set preferred and minimum sizes as well as make your frame big enough.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Carey, you might want to choose a different layout manager for that JPanel container, if you want to control the gap between the two grids. It looks to me like FlowLayout is the default manager for JPanel, but using a FlowLayout with specified gap sizes might answer wesley's question, I think.
 
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And that holds for the panels that contain all those lines too. You can get the same layout by using a GridLayout of sufficient rows and columns, with horizontal and vertical spacing of 1 (or whatever thickness), on a panel with black background. Fill it with opaque JLabels with backgroundcolor as suited. No need for size calculations or nasty paintComponent methods.
reply
    Bookmark Topic Watch Topic
  • New Topic