for some reason my insets aren't resetting after I set the values back to 0. My intention is to move one button, for example, to the left 200 pixels, an then reset that straight after so that any other components are not moved 200 pixels. The problem being that even though I redefine my insets as being 0,0,0,0 both components are being moved. Thank's for any answers!
Here's the code that I use to initiate the JPanel that has the problem :
import java.awt.BorderLayout;
import java.io.IOException;
import javax.swing.JComponent;
import javax.swing.JFrame;
public class MainFrame {
public static void main(String[] args) throws IOException {
MainFrame gui = new MainFrame();
gui.Frame();
}
public JFrame Frame() throws IOException {
JFrame frame = new JFrame("");
PlayGamePanel passme = new PlayGamePanel();
JComponent panel2 = passme.GamePanel2(frame);
frame.add(panel2);
frame.getContentPane().add(BorderLayout.CENTER, panel2 );
frame.setSize(860,500);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setVisible(true);
frame.getContentPane().add(panel2, BorderLayout.CENTER);
return frame;
}
}
Here's my code that has the inset problem :
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.image.BufferedImage;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
@SuppressWarnings("serial")
public class PlayGamePanel extends JComponent{
JComponent GamePanel2() throws IOException {
JComponent GamePanel = new JLabel();
//Setting up the GridBagLayout
GamePanel.setLayout(new GridBagLayout());
GridBagConstraints gbLayout = new GridBagConstraints();
//Creating the buttons + setting up the GridBagConstraints
gbLayout.insets = new Insets(300, 350, 0, 450);
JButton AnswerOneButton = new JButton("")
GamePanel.add(AnswerOneButton, gbLayout);
gbLayout.insets = new Insets(0, 0, 0, 0);
JButton AnswerTwoButton = new JButton("1");
GamePanel.add(AnswerTwoButton, gbLayout);