java - Adding panels to JScroll -


i have made application has 3 panels. status, btn , top panel. have buttons added btn panel , labels in status panel , text fields in top panel. of these panels added jframe. wanted put of jscroller. unsure on how this, appreciated. added code showing how laid out.

static flowlayout toppanellayout = new flowlayout(); static gridlayout parentlayout = new gridlayout(0,1); static gridlayout statuslayout = new gridlayout(2,1); static jframe frame = new jframe("web api interface"); static jpanel statuspanel; static jpanel btnpanel; static jpanel toppanel;       frame.setlayout(parentlayout);      // -- create panels     toppanel = new jpanel(toppanellayout);     statuspanel = new jpanel(statuslayout);     btnpanel = new jpanel(new gridlayout(0,2));      frame.setsize(1100,600);     frame.setdefaultcloseoperation(jframe.exit_on_close); statuspanel.add(statuslabel);     statuspanel.add(connectionstatuslabel);     statuspanel.add(cidlabel);      // -- add label , textfield @ top panel @ top of     //    frame     toppanel.add(new jlabel("enter ip:"));     toppanel.add(ipaddressfield);        // -- 1.) add top panel .... goes in order down     frame.getcontentpane().add(toppanel);     frame.getcontentpane().add(statuspanel);     frame.getcontentpane().add(btnpanel);     //display window.     frame.setvisible(true); 

jscroller

what jscroller??? use proper class names know talking about.

don't add 3 panels frame.

instead add 3 panel panel. create jscrollpane using panel , add scroll pane frame:

//frame.getcontentpane().add(toppanel); //frame.getcontentpane().add(statuspanel); //frame.getcontentpane().add(btnpanel); jpanel parent = new jpanel( parentlayout ); parent.add( toppanel ); parent.add( statuspanel ); parent.add( btnpanel ); frame.add( new jscrollpane( parent ) ); 

also, rid of static variables. there no need variables static if code designed properly.