java - My main class doesn't seem to add a object -
i'm kind of new-ish java.
i'm trying add footer jpanel swing app. i'm doing having jpanel footer in separate class.
this footerbar-class has jpanel properties in it:
public class footerbar extends jpanel { private jpanel footerpanel = new jpanel(); private jlabel label; public footerbar() { // footer test footerpanel.setpreferredsize(new dimension(640, 16)); footerpanel.setlayout(new boxlayout(footerpanel, boxlayout.x_axis)); footerpanel.setborder(new bevelborder(bevelborder.lowered)); jlabel label; label = new jlabel("test"); label.sethorizontalalignment(swingconstants.left); footerpanel.add(label); label = new jlabel("test 2"); label.sethorizontalalignment(swingconstants.center); footerpanel.add(label); } }
and have in main class. (called mainframe)
public class mainframe extends jframe { private textpanel textpanel = new textpanel(); private toolbar toolbar = new toolbar(); private formpanel formpanel = new formpanel(); private footerbar footerpanel = new footerbar(); private static string windowtitle = "win7 usb3 installer"; /** * properties window */ public mainframe() { super(windowtitle); setlayout(new borderlayout()); add(formpanel, borderlayout.west); add(textpanel, borderlayout.center); add(footerpanel, borderlayout.south); }
}
if had jpanel properties inside main class, works perfectly. doesn't show jpanel 2 different classes.
though other components move bit, won't collide jpanel. guess doesn't initialize actual jpanel. why that?
your footerbar
jpanel
, creating jpanel
, adding things has no use, use footerbar
panel directly :
public class footerbar extends jpanel { private jlabel label; public footerbar() { // footer test setpreferredsize(new dimension(getwidth(), 16)); setlayout(new boxlayout(this, boxlayout.x_axis)); setborder(new bevelborder(bevelborder.lowered)); jlabel label; label = new jlabel("test"); label.sethorizontalalignment(swingconstants.left); add(label); label = new jlabel("test 2"); label.sethorizontalalignment(swingconstants.center); add(label); } }
Comments
Post a Comment