Hi
I am creating a simple gui. Right now i just insert buttons inside the gridbag cells and i have this goal:
(--|--|--)(--) <-button "Start"
(-bigone-)(--) <-button "Stats"
(--|--|--)(--) <-button "Spells"
|
button "action"
So that schema means that i have:
-big button "action" (0,0) that spans 3 rows and 3 cols
-button "Start" that that is on 4th column and 1st row (0,3)
-button "Stats" (1,3)
-button "Spells" (2,3)
ok, but with the code below i get this result:
(--|--)(--|--) <-Start
(--|--)(--|--) <-Stats
(--|--)(--|--) <-Spells
|
Action
That means button action only spans 2 cols instead of 3 and
rest of three buttons are allso 2 cols wide instead of 1. But rowspan
is ok.
Here is the code:
import java.awt.*;
import javax.swing.*;
public class hero extends JFrame{
public static void main(
String[] args){
hero h = new hero();
}
public hero(){
JFrame f=new JFrame("Hero ... early development");
f.setSize(640,480);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
f.setResizable(false);
f.setLocation(100, 100);
Container container=f.getContentPane();
GridBagLayout GB = new GridBagLayout();
container.setLayout(GB);
GridBagConstraints c= new GridBagConstraints();
c.weightx = 1;//fill x
c.weighty = 1;//fill y
c.fill=GridBagConstraints.BOTH;//lauotab componendid laiali
c.gridheight=3;
c.gridwidth=3;
c.gridx=0;
c.gridy=0;
Button b1=new Button("Action");
GB.setConstraints(b1, c);
container.add(b1);
c.gridheight=1;
c.gridwidth=1;
c.gridx=3;
c.gridy=0;
Button b2=new Button("Start");
GB.setConstraints(b2, c);
container.add(b2);
c.gridx=3;
c.gridy=1;
Button b3=new Button("Stats");
GB.setConstraints(b3, c);
container.add(b3);
c.gridx=3;
c.gridy=2;
Button b4=new Button("Spells");
GB.setConstraints(b4, c);
container.add(b4);
f.setVisible(true);
}
}
//end
please help me ... thnx
[ December 26, 2003: Message edited by: Juhan Voolaid ]