java - Arrange the Label with its respective field Swing -
i need align fields respective labels,
here code :
public class progress extends jpanel implements actionlistener { public jlabel clientip; jtextfield ip; jlabel clientpassword; jtextfield pass; jlabel videoname; jtextfield vname; jlabel perccomplete; jtextfield percent; jlabel packetssent; jtextfield pacsent; jlabel connectiontype; jtextfield conntype; jlabel noofvideossent; jtextfield videosend; jbutton disconnect; jbutton refresh; jbutton ok; public progress() { clientip = new jlabel("client's ip:"); clientpassword = new jlabel("clients password:"); videoname = new jlabel("video being transfered:"); perccomplete = new jlabel("% of transfer complete:"); packetssent = new jlabel("no of packets sent:"); connectiontype = new jlabel("connection type:"); noofvideossent = new jlabel("no of videos sent:"); string ipad,ipass,iselvid; if(clientipaddr==null || clientipaddr.equals("")){ ipad="not connected"; }else ipad=clientipaddr.tostring(); if(vfilepassword ==null || vfilepassword.equals("")){ ipass="no password"; }else ipass=vfilepassword; if(selected_video==null || selected_video.equals("")){ iselvid="not selected"; }else iselvid=selected_video; ip = new jtextfield(ipad); ip.setcolumns(20); pass = new jtextfield(ipass); pass.setcolumns(20); vname = new jtextfield(iselvid); vname.setcolumns(20); percent = new jtextfield("10%"); percent.setcolumns(20); pacsent =new jtextfield(string.valueof(rtspseqnb)); pacsent.setcolumns(20); string c; if(clientconnected==true) c="tcp"; else c="not connected"; conntype = new jtextfield(c); conntype.setcolumns(20); videosend = new jtextfield(string.valueof(videocount)); videosend.setcolumns(20); //tell accessibility tools label/textfield pairs. clientip.setlabelfor(ip); clientpassword.setlabelfor(pass); videoname.setlabelfor(vname); perccomplete.setlabelfor(percent); packetssent.setlabelfor(pacsent); connectiontype.setlabelfor(conntype); noofvideossent.setlabelfor(videosend); //lay out labels in panel. jpanel labelpane = new jpanel(new gridlayout(0,1)); labelpane.add(clientip); labelpane.add(clientpassword); labelpane.add(videoname); labelpane.add(perccomplete); labelpane.add(packetssent); labelpane.add(connectiontype); labelpane.add(noofvideossent); //layout text fields in panel. jpanel fieldpane = new jpanel(new gridlayout(0,1)); fieldpane.add(ip); fieldpane.add(pass); fieldpane.add(vname); fieldpane.add(percent); fieldpane.add(pacsent); fieldpane.add(conntype); fieldpane.add(videosend); //put panels in panel, labels on left, //text fields on right. //setborder(borderfactory.createemptyborder(20, 20, 20, 20)); jpanel buttonpane = new jpanel(new gridlayout(0,1)); disconnect = new jbutton("disconnect client"); disconnect.setactioncommand("disconnect"); disconnect.addactionlistener(this); refresh = new jbutton("refresh details"); refresh.setactioncommand("refresh"); refresh.addactionlistener(this); ok = new jbutton("ok"); ok.setactioncommand("ok"); ok.addactionlistener(this); buttonpane.add(refresh); buttonpane.add(disconnect); buttonpane.add(ok); add(labelpane, borderlayout.center); add(fieldpane, borderlayout.line_end); add(buttonpane, borderlayout.after_last_line); } private void createandshowgui() { //create , set window. frame = new jframe("connected client's details"); //frame.setdefaultcloseoperation(jframe.exit_on_close); //add contents window. frame.add(new progress()); //display window. frame.pack(); frame.setvisible(true); }
i tried going referencing not working, suggestions ?
look @ example given grouplayout
(picture link):
your code should closely resemble code link.
Comments
Post a Comment