java - Why JLabel has zero height when using SpringLayout? -


i new in java ui design , try use springlayout create form. put jlabel in jframe, added constraints. need jlabel stratches jpanel width. has 0 height. , small width.

here code fragment:

imagecontainer = new jlabel(); imagecontainer.setborder(borderfactory.createlineborder(color.black));  filterbutton = new jbutton("filter"); filterbutton.addactionlistener(filter);  layout.putconstraint(springlayout.west, imagecontainer, 5, springlayout.west, this); layout.putconstraint(springlayout.north, imagecontainer, 5, springlayout.north, this); layout.putconstraint(springlayout.east, imagecontainer, 5, springlayout.east, this);  layout.putconstraint(springlayout.west, filterbutton, 5, springlayout.west, this); layout.putconstraint(springlayout.north, filterbutton, 5, springlayout.south, imagecontainer); layout.putconstraint(springlayout.south, filterbutton, 5, springlayout.south, this); 

and result

where did go wrong? how stretch jlabel size parent container?

my problem not in jlablel. attempted use this in constraints it's not correct way. need container this:

container contentpane = this.getcontentpane(); 

after can use contentpane in constraints:

layout.putconstraint(springlayout.west, imagecontainer, 5, springlayout.west, contentpane); layout.putconstraint(springlayout.north, imagecontainer, 5, springlayout.north, contentpane); layout.putconstraint(springlayout.east, imagecontainer, -5, springlayout.east, contentpane); layout.putconstraint(springlayout.south, imagecontainer, -5, springlayout.north, filterbutton);  layout.putconstraint(springlayout.west, filterbutton, 5, springlayout.west, contentpane); layout.putconstraint(springlayout.south, filterbutton, -5, springlayout.south, contentpane); 

and work.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -