|
I'm trying to use the GridBagLayout for a panel i'm designing. The problem is that when I compile and run the app, the JButton gets placed directly in the middle of the panel, instead of at 0,0 like I coded it to. Can someone tell me what's wrong with this code?? Here are the two methods that use the GridBagLayout..
[code] import javax.swing.JPanel; import javax.swing.JButton; import java.awt.Color; import java.awt.image.BufferedImage; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Insets;
public class BlackjackPanel extends JPanel { private BufferedImage picOfMe; private BufferedImage logo; private BufferedImage dealBtnPic; private BufferedImage hitBtnPic; private BufferedImage stayBtnPic; private BufferedImage splitBtnPic;
private JButton deal; private JButton hit; private JButton stay; private JButton split;
public BlackjackPanel() { setLayout(new GridBagLayout());
//dark green setBackground(new Color(0, 153, 51));
deal = new JButton("Deal"); add(deal, getConstraints(0,0,5,5,GridBagConstraints.CENTER)); }//end BlackjackPanel c'tor
private GridBagConstraints getConstraints(int gridx, int gridy, int gridWidth, int gridHeight, int anchor) { GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(5, 5, 5, 5); c.ipadx = 0; c.ipady = 0; c.gridx = gridx; c.gridy = gridy; c.gridwidth = gridWidth; c.gridheight = gridHeight; c.anchor = anchor;
return c; }//end getConstraints
}//end BlackjackPanel
This post has been edited by kwikness: 20 May, 2007 - 12:18 AM
|