M
Mr. X.
Helo,
I think that gridBagLayout is the most complicated of the standard layouts.
I try to understand the following (see my thoughts after the asterisks ...)
:
// (The code is a class that implements the JPanel)
protected void makebutton(String name,
GridBagLayout gridbag,
GridBagConstraints c) {
JButton button = new JButton(name);
gridbag.setConstraints(button, c);
add(button);
button.addActionListener(this);
}
public void initX() {
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setFont(new Font("SansSerif", Font.PLAIN, 14));
setLayout(gridbag);
setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
c.anchor = GridBagConstraints.LINE_END;
c.weightx = 1;
c.weighty = 1;
c.fill = GridBagConstraints.VERTICAL;
c.anchor = GridBagConstraints.EAST;
makebutton("ButtonX", gridbag, c);
c.weightx = 1;
c.weighty = 1;
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.BOTH;
c.anchor = GridBagConstraints.EAST;
makebutton("ButtonY", gridbag, c);
// *********************************
// *********************************
// *********************************
// ...
All I want to do is that : ButtonX will be at the east side of the panel,
and ButtonY will be at the rest of the panel.
What I get is that buttonX is OK, but buttonY is from left to a place where
the button seems as a square (what ever I try to do ...)
Since I am new to gridbaglayout , I need help of the above code, please.
I would like a good tutorial (that explains with some examples, every method
& field of GridBagConstraint), please.
What's wrong with my code ?
Thanks
I think that gridBagLayout is the most complicated of the standard layouts.
I try to understand the following (see my thoughts after the asterisks ...)
:
// (The code is a class that implements the JPanel)
protected void makebutton(String name,
GridBagLayout gridbag,
GridBagConstraints c) {
JButton button = new JButton(name);
gridbag.setConstraints(button, c);
add(button);
button.addActionListener(this);
}
public void initX() {
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setFont(new Font("SansSerif", Font.PLAIN, 14));
setLayout(gridbag);
setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
c.anchor = GridBagConstraints.LINE_END;
c.weightx = 1;
c.weighty = 1;
c.fill = GridBagConstraints.VERTICAL;
c.anchor = GridBagConstraints.EAST;
makebutton("ButtonX", gridbag, c);
c.weightx = 1;
c.weighty = 1;
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.BOTH;
c.anchor = GridBagConstraints.EAST;
makebutton("ButtonY", gridbag, c);
// *********************************
// *********************************
// *********************************
// ...
All I want to do is that : ButtonX will be at the east side of the panel,
and ButtonY will be at the rest of the panel.
What I get is that buttonX is OK, but buttonY is from left to a place where
the button seems as a square (what ever I try to do ...)
Since I am new to gridbaglayout , I need help of the above code, please.
I would like a good tutorial (that explains with some examples, every method
& field of GridBagConstraint), please.
What's wrong with my code ?
Thanks