java - How can i show the jpanel? -


i make movie theater system. , keep movies , movie theaters in jtable. i'm trying show movie theater. movie theater seats made jbutton , keep these seats in jpanel.

how can show seats when movie theater selected?

and code.

final arraylist<jpanel> panels = new arraylist<>();       for(int k=0;k<theater.size();k++){         jpanel panel = new jpanel();         panel.setbounds(500, 0, 500, 500);         contentpane.add(panel);          int y = theater.get(k).getcapacity();         int x = 500/y;                    for(int i=0;i<y;i++){             for(int j=0;j<y;j++){                 jbutton button = new jbutton(letters[i]+numbers[j]);                 button.setbounds(500 + x*j, 0 + x*i, x-5, x-5);                 panel.add(button);             }         }         repaint();         panels.add(panel);           } 

don't use setbounds() method instead leave layout manger set size , position of components why it's made for.

use proper layout design such gridlayout, gridbaglayout etc.

read more layout how use various layout managers


don't directly add components in jframe's content pane instead first add components in container such jpanel add in jframe's content pane.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -