java - JSplitPane not filling panel -
i having trouble making jsplitpane
work how too.
first, fill container (a jframe) fully, not have size determined components inside the split panes. second, when resize container, not display scroll bar on either jscrollpane
s or jlist
s.
any ideas how make happen. i'm sure need wire listeners correctly, i'm not quite sure start.
my panel looks this...
public class mainpanel extends jpanel { public mainpanel(){ jpanel p1 = new jpanel(); jpanel p2 = new jpanel(); jpanel p3 = new jpanel(); p1.setlayout(new boxlayout(p1, boxlayout.page_axis)); p2.setlayout(new boxlayout(p2, boxlayout.page_axis)); p3.setlayout(new boxlayout(p3, boxlayout.page_axis)); p1.add(new somebuttons()); p2.add(new somebuttons()); p3.add(new somebuttons()); p1.add(newneedylist()); p2.add(newneedylist()); p3.add(newneedylist()); dimension ms = new dimension(0,0); p1.setminimumsize(ms); p2.setminimumsize(ms); p3.setminimumsize(ms); p1.setbackground(color.red); p2.setbackground(color.green); p3.setbackground(color.blue); jscrollpane scp1 = new jscrollpane(p1); jscrollpane scp2 = new jscrollpane(p2); jscrollpane scp3 = new jscrollpane(p3); scp1.setverticalscrollbarpolicy(jscrollpane.vertical_scrollbar_never); scp2.setverticalscrollbarpolicy(jscrollpane.vertical_scrollbar_never); scp3.setverticalscrollbarpolicy(jscrollpane.vertical_scrollbar_never); scp1.sethorizontalscrollbarpolicy( jscrollpane.horizontal_scrollbar_as_needed); scp2.sethorizontalscrollbarpolicy( jscrollpane.horizontal_scrollbar_as_needed); scp3.sethorizontalscrollbarpolicy( jscrollpane.horizontal_scrollbar_as_needed); jsplitpane sp1 = new jsplitpane(jsplitpane.horizontal_split,scp2,scp3); jsplitpane sp2 = new jsplitpane(jsplitpane.horizontal_split,scp1,sp1); sp1.setdividerlocation(0.5); sp2.setdividerlocation(0.333333333); sp2.setresizeweight(0.333333333); sp1.setresizeweight(1.0); this.add(sp2, borderlayout.center); } /** buttons... part fill panel how want */ private class somebuttons extends jpanel{ public somebuttons(){ this.setlayout(new boxlayout(this, boxlayout.line_axis)); this.add(new jlabel("stuff:")); for(int i=0; i<5; i++){ final jbutton btn = new jbutton(" "+i+" "); btn.addactionlistener(new actionlistener(){ @override public void actionperformed(actionevent ae) { joptionpane.showmessagedialog(btn, "feck off!", "you have pressed button", joptionpane.warning_message); } }); this.add(btn); } } } private jlist newneedylist(){ string[] s = new string[7]; s[0] = "choose me!"; (int i=1; i<7; i++){ s[i] = "no! choose me!"; } return new jlist(s); } }
at moment have in jframe
public class threepanelstest { public static void main(string[] args) { jframe frame = new jframe(); mainpanel panel = new mainpanel(); frame.add(panel); frame.setsize(1000,600); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setvisible(true); } }
i think don't need add mainpanel class, instead, add components add mainpanel object directly contentpane of jframe...
final container contentpane = this.getcontentpane(); contentpane.setlayout(new borderlayout(2, 2));
Comments
Post a Comment