Source Code : A GridBagLayout Example: weightx, weighty
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
A GridBagLayout Example: weightx, weighty
import java.awt.Button;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JPanel;
public class Main extends JPanel {
protected void makebutton(String name, GridBagLayout gridbag, GridBagConstraints c) {
Button button = new Button(name);
gridbag.setConstraints(button, c);
add(button);
}
public Main() {
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setLayout(gridbag);
c.weightx = 1.0;
c.weighty = 1.0;
makebutton("Button 1", gridbag, c);
c.fill = GridBagConstraints.BOTH;
makebutton("Button 2", gridbag, c);
}
public static void main(String args[]) {
Frame f = new Frame();
JPanel mgb = new Main();
f.add("Center", mgb);
f.pack();
f.setSize(300, 300);
f.setVisible(true);
}
}
Thank with us