java - Why is this GridBagConstraints code not working? -


hello wanted add text area, text field , button panel. wanted area use 3/4 of height , full width, field use 1/4 of height , 3/4 of width , button use 1/4 height , 1/4 width. post pic show want get. code looks like:

// jpanel class public mainpanel() {    setlayout(new gridbaglayout());    add(area, new gbc(0, 0, 4, 3).setweight(4,4).setfill(gbc.both));    add(field, new gbc(0, 3, 3, 1).setweight(1,1).setfill(gbc.horizontal)); } 

gbc class inherits gridbagconstraints class:

public class gbc extends gridbagconstraints {     public gbc(int gridx, int gridy) {       this.gridx = gridx;       this.gridy = gridy;       weightx = 100;       weighty = 100;    }     public gbc(int gridx, int gridy, int gridwidth, int gridheight) {       this(gridx, gridy);       this.gridwidth = gridwidth;       this.gridheight = gridheight;    }     public gbc setfill(int fill) {       this.fill = fill;       return this;    } } 

enter image description here

so problem both area , field take half of height , button in center, hidden under field... terrible anyway, how solve if?

that's how should like:

add(area, new gbc(0, 0, 4, 3).setweight(4,4).setfill(gbc.both)); add(field, new gbc(0, 3, 3, 1).setweight(1,1).setfill(gbc.horizontal)); 

also read weightx , weighty, cause you're using them in wrong way


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -