java - Too much space between components in Spring layout -


i want create jframe hand , use spring layout this. but, output not good. space between rows much, , between radio buttons too:

example output

my code:

public final class newuserframe1 extends jframe {  public newuserframe1() {     add(rowcomponent(), borderlayout.center);     setlocation(200, 40);     setdefaultcloseoperation(jframe.exit_on_close);     setresizable(false);     setvisible(true);     pack(); }  public jpanel rowcomponent() {      jpanel panel = new jpanel();     jlabel fnamelbl = new jlabel("first name");     jlabel lnamelbl = new jlabel("last name");     jlabel fntemp = new jlabel();     jlabel lntemp = new jlabel();     jtextfield fntf = new jtextfield(10);     jtextfield lntf = new jtextfield(10);     jlabel gndlnl = new jlabel("gender");     jradiobutton malerb = new jradiobutton("male");     jradiobutton femalerb = new jradiobutton("female");     buttongroup bgroup = new buttongroup();     bgroup.add(malerb);     bgroup.add(femalerb);     jlabel registnm = new jlabel("registration id is:");     jlabel showreglbl = new jlabel();     jlabel regtemp = new jlabel();      panel.add(fnamelbl);     panel.add(fntf);     panel.add(fntemp);     panel.add(lnamelbl);     panel.add(lntf);     panel.add(lntemp);     panel.add(gndlnl);     panel.add(malerb);     panel.add(femalerb);     panel.add(registnm);     panel.add(showreglbl);     panel.add(regtemp);      panel.setlayout(new springlayout());     springutilities.makecompactgrid(panel, 4, 3, 50, 15, 3, 4);     return panel; }  public static void main(string[] args) {     swingutilities.invokelater(new runnable() {         @override         public void run() {             newuserframe1 newuserframe1 = new newuserframe1();         }     }); } } 

now: enter image description here

instead of calling setsize call pack on jframe within newuserframe1 constructor.

public newuserframe1() {     add(rowcomponent(), borderlayout.center);     setlocation(200, 40);     //setsize(800, 500);     setdefaultcloseoperation(jframe.exit_on_close);     setresizable(false);     setvisible(true);     pack(); } 

also change parameters of springutilities.makecompactgrid method in following way:

springutilities.makecompactgrid(panel, 4, 3, 50, 15, 3, 4);//change ypad 4 instead of 100. sets vertical height between 2 rows 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -