java - JList Left Attached and Filled -


    setlayout(new borderlayout());     add(listscroller, borderlayout.west); 

when list being left attached , filled column size. when add more things.

    setlayout(new gridbaglayout());     gridbagconstraints gc = new gridbagconstraints();      gc.gridx = 2;     gc.gridy = 0;     add(namelabel, gc); 

it's being smaller , when resize turns unvisible. how can fit list on left, other thing on right.

extra question: if there few elements in list, scroller doesn't show. wanna see scroller whatever happens.

to start with, might use single layout manager...

setlayout(new gridbaglayout()); gridbagconstraints gc = new gridbagconstraints();  gc.gridx = 0; gc.gridy = 0; gc.weighty = 1; gc.fill = gridbagconstraints.both; gc.gridheight = gridbagconstraints.remainder; add(listscroller, gc);  gc.gridx = 2; gc.gridy = 0; gc.weighty = 0; gc.fill = gridbagconstraints.none; gc.gridheight = 1; add(namelabel, gc); 

or

setlayout(new borderlayout()); add(listscroller, borderlayout.west); add(namelabel); 

depending on want achieve

see laying out components within container more details

extra question: if there few elements in list, scroller doesn't show. wanna see scroller whatever happens.

you want take @ jscrollpane#setverticalscrollbarpolicy , jscrollpane#sethorizontalscrollbarpolicy


Comments