java - JPanel Not Stretching To Fill Screen -


so trying make panel stretches across entire programs with, , has 20 pixels worth of height. reason there small box panel. can tell me why isn't stretching entire width? i'm new java, sorry if code little messy/wrong.

gridpane class

public gridpane() {   gbc = new gridbagconstraints();   gbc.anchor = gridbagconstraints.north;   gbc.weighty = 1.0;   horizontalgrid = new jbutton();   horizontalgrid.settext("horizontal grid");   options = new jpanel(new borderlayout());   options.setbackground(color.black);   options.add(horizontalgrid);   add(options, gbc); } 

game class

public class game extends jpanel implements actionlistener{    //declarations private static final long serialversionuid = 1l;     public gridpane grid = new gridpane(); //declarations end //constructor public game() {     this.add(grid);      } //constructor ends //main method public static void main(string[] args) {     jframe frame = new jframe();     game game = new game();     frame.setresizable(true);     frame.setalwaysontop(true);     frame.setdefaultcloseoperation(jframe.exit_on_close);     frame.add(game);     frame.pack();     frame.setlocationrelativeto(null);     frame.setvisible(true); } //main method ends //action method public void actionperformed(actionevent e) { } 

i fixed it!! turns out needed replace gridpane constructor code:

setbackground(color.black);  add(horizontalgrid); 

i'm not sure why, works.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -