JScroll don't work in right panel JSplitPane - Swing Java -


can me problem? write layout bittorrent's client , don't have idea why jscroll doesn't work in right panel jsplitpane. more code here: https://github.com/niesuch/bittorrentclient/blob/nie_bittorrentclient/src/bittorrent.java in advance.

    /**      * initialization information panel      */     private void _initinfopanel() {         jpanel formpanel = new jpanel();         formpanel.setborder(borderfactory.createtitledborder("informations"));          jpanel form = new jpanel(new gridlayout(0, 2));          int = 0;         (string formlabel : _formlabels) {             form.add(new jlabel(formlabel));             _textfields[i] = new jtextfield(10);             form.add(_textfields[i++]);         }          formpanel.add(form);                 _infopanel.add(formpanel);                 _infopanel.add(new jscrollpane(formpanel), borderlayout.center);      } 

my minimal example program:

import java.awt.borderlayout; import java.awt.gridlayout; import javax.swing.borderfactory; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jpanel; import javax.swing.jscrollpane; import javax.swing.jsplitpane; import javax.swing.jtextfield;  public class test extends jframe {     private final jpanel _downloadspanel;     private final jpanel _buttonspanel;     private final jpanel _infopanel;     private final jtextfield[] _textfields;     private final string[] _formlabels =     {         "name: ", "size: ", "% downloaded: ", "status: ",         "download: ", "upload: ", "time remaining: ", "pieces: ",         "peer data including ip addresses: ", "speed download them: ",         "speed upload them: ", "port using: ", "port client: "     };     private jbutton _pausebutton;      public test() {         settitle("bittorrent");         setsize(1024, 768);          _downloadspanel = new jpanel();         _buttonspanel = new jpanel();         _infopanel = new jpanel();         _textfields = new jtextfield[_formlabels.length];          jsplitpane splitpane = new jsplitpane(jsplitpane.horizontal_split, _downloadspanel, _infopanel);         splitpane.setresizeweight(0.7);          _initinfopanel();         _initbuttonspanel();          getcontentpane().setlayout(new borderlayout());         getcontentpane().add(_buttonspanel, borderlayout.south);         getcontentpane().add(splitpane, borderlayout.center);             }      private void _initinfopanel()     {         jpanel formpanel = new jpanel();         formpanel.setborder(borderfactory.createtitledborder("informations"));          jpanel form = new jpanel(new gridlayout(0, 2));          int = 0;         (string formlabel : _formlabels)         {             form.add(new jlabel(formlabel));             _textfields[i] = new jtextfield(10);             form.add(_textfields[i++]);         }          formpanel.add(form);                 _infopanel.add(formpanel);                 _infopanel.add(new jscrollpane(formpanel), borderlayout.center);      }       private void _initbuttonspanel()     {         _pausebutton = new jbutton("pause");         _pausebutton.setenabled(false);         _buttonspanel.add(_pausebutton);      }      public static void main(string[] args)     {         test bittorrent = new test();         bittorrent.setvisible(true);     }  } 

it's simple error. you're treating _infopanel if uses borderlayout, e.g.,

_infopanel.add(new jscrollpane(formpanel), borderlayout.center); //!! 

but doesn't , instead uses jpanel's default flowlayout:

_infopanel = new jpanel();  

flowlayout display components @ preferredsizes, , not try shrink or expand them, , jscrollpane not change size. make obvious change:

_infopanel = new jpanel(new borderlayout());  

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -