java - Adding Jpanel containing JButton disturbs the structure of frame -
class frame extends jframe{ public frame() { jframe jf= new jframe("student admission"); jf.setlayout(new gridlayout(5,1)); jpanel jpn= new jpanel(); jpanel enr= new jpanel(); enr.setlayout(new flowlayout(flowlayout.left)); jlabel enrno= new jlabel("enrollment number",jlabel.left); jtextfield enrnoinput=new jtextfield(3); enr.add(enrno); enr.add(enrnoinput); jf.add(enr); jlabel name= new jlabel("student's name",jlabel.left); jtextfield nameinput=new jtextfield(60); jpn.add(name); jpn.add(nameinput); jf.add(jpn); jpanel jpfn= new jpanel(); jlabel fname= new jlabel("fathers's name",jlabel.left); jtextfield fnameinput=new jtextfield(60); jpfn.add(fname); jpfn.add(fnameinput); jf.add(jpfn); jpanel hscp= new jpanel(); hscp.setlayout(new flowlayout(flowlayout.left)); jlabel hscper= new jlabel("hsc percentage",jlabel.left); jtextfield hscperinput=new jtextfield(3); hscp.add(hscper); hscp.add(hscperinput); jf.add(hscp); jpanel sscp= new jpanel(); sscp.setlayout(new flowlayout(flowlayout.left)); jlabel sscper= new jlabel("ssc percentage",jlabel.left); jtextfield sscperinput=new jtextfield(3); sscp.add(sscper); sscp.add(sscperinput); jf.add(sscp); //after adding panel frame's structure disturbed jpanel buttonpanel= new jpanel(); jbutton save= new jbutton("save"); jbutton cancel= new jbutton("cancel"); buttonpanel.add(save); buttonpanel.add(cancel); jf.add(buttonpanel); jf.setresizable(false); jf.pack(); jf.setvisible(true); jf.setdefaultcloseoperation(exit_on_close); } }
before adding buttonpanel
after adding buttonpanel
i want add button panel in middle-bottom of frame how can that?
your grid layout accounts 5 components, it's screwing when use 6. add buttonpanel
sscp
panel , add sscp
panel overall frame.
jpanel sscp= new jpanel(); sscp.setlayout(new flowlayout(flowlayout.left)); jlabel sscper= new jlabel("ssc percentage",jlabel.left); jtextfield sscperinput=new jtextfield(3); sscp.add(sscper); sscp.add(sscperinput); jpanel buttonpanel= new jpanel(); jbutton save= new jbutton("save"); jbutton cancel= new jbutton("cancel"); buttonpanel.add(save); buttonpanel.add(cancel); //change here sscp.add(buttonpanel); jf.add(sscp);
Comments
Post a Comment