Java Swing Layouts and Menus -


ok having trouble using grid layout arrange window in format, want arrange each label , text field individual line , have centered button @ bottom.

  public class main extends jframe {     //below how want format frame         /*label textfield           label textfield              label textfield                  button*/           jpanel panel = new jpanel();         jlabel namelabel = new jlabel("name");         jtextfield nametext = new jtextfield(15);         jlabel addresslabel = new jlabel("address");         jtextfield addresstext = new jtextfield(15);          public main(){             settitle("jswing");             setlayout(new gridlayout(3,2));             setcomponentorientation(componentorientation.left_to_right);             setvisible(true);             setsize(450,250);           //setresizable(false);             setdefaultcloseoperation(exit_on_close);              panel.add(namelabel);             panel.add(nametext);             panel.add(addresslabel);             panel.add(addresstext);               add(panel);         }         public static void main(string[] args){             main mainframe = new main();             //mainframe.setvisible(true);         }     } 

//setvisible(true); // don't until components added frame. ... add(panel, borderlayout.center); jpanel buttonpanel = new jpanel(); jbutton button = new jbutton("button"); buttonpanel.add( button ); add(buttonpanel, borderlayout.page_end); setvisible(true); 

the default layout manager frame borderlayout. can add multiple panels frame. 1 panel containing labels/text fields , other containing button.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -