swing - In Java, what is the default JPanel height and width? -


i have created class below. when create object called drawpanel of class , add frame using frame.getcontentpane().add(borderlayout.center, drawpanel), rectangle black background expected. mean panel's this.getwidth , this.getheight default has same height , width of frame (which why fills entire frame black colour) ?

one other way want reframe question - if create custom widget extending jpanel, , when custom widget instantiated, default height , width ?

import java.awt.color; import java.awt.graphics; import javax.swing.jpanel;  public class mydrawpanel extends jpanel { public void paintcomponent(graphics g){     g.fillrect(0, 0, this.getwidth(), this.getheight());     } } 

i think jpanel has prefered size of 0,0. if add components higher prefered size, prefered size not 0.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -