Hi,
I'm having an issue with my GUI, where 2 of the buttons appear to be overlapping. I'm trying to get the buttons to span multiple columns. It works on the other 2 buttons, but not on this one; which is weird because i practially copy and pasted the code.
I've been trying to debug this stupid button for 45min now, but with no luck. Can someone please take a look at the code and let me know what the problem is? The 'Solve' button (jSolve) overlaps with the 'EXIT' (jExit) button.
Thank you.
public class test extends JFrame { JTextField jHex1; JTextField jHex2; JTextField jHex3; JTextField jHex4; JTextField jHex5; JTextField jHex6; JTextField jHex7; JTextArea jResult; JButton jClear; JButton jSolve; JButton jExit; test() { JPanel p1 = new JPanel(); p1.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(6,6,3,3); jHex1 = new JTextField(12); jHex2 = new JTextField(12); jHex3 = new JTextField(12); jHex4 = new JTextField(12); jHex5 = new JTextField(12); jHex6 = new JTextField(12); jHex7 = new JTextField(12); jResult = new JTextArea(); jClear = new JButton("Clear"); jSolve = new JButton("Solve"); jExit = new JButton("EXIT"); JLabel label1 = new JLabel("Hex 1:"); JLabel label2 = new JLabel("Hex 2:"); JLabel label3 = new JLabel("Hex 3:"); JLabel label4 = new JLabel("Hex 4:"); JLabel label5 = new JLabel("Hex 5:"); JLabel label6 = new JLabel("Hex 6:"); JLabel label7 = new JLabel("Hex 7:"); c.gridx = 0; c.gridy = 3; p1.add(label1, c); c.gridx = 3; c.gridy = 3; p1.add(jHex1, c); c.gridx = 0; c.gridy = 6; p1.add(label2, c); c.gridx = 3; c.gridy = 6; p1.add(jHex2, c); c.gridx = 0; c.gridy = 9; p1.add(label3, c); c.gridx = 3; c.gridy = 9; p1.add(jHex3, c); c.gridx = 0; c.gridy = 12; p1.add(label4, c); c.gridx = 3; c.gridy = 12; p1.add(jHex4, c); // ****** Solve Button ******* c.weightx = 0.0; c.gridwidth = GridBagConstraints.RELATIVE; c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 15; p1.add(jSolve, c); c.gridx = 15; c.gridy = 3; p1.add(label5, c); c.gridx = 18; c.gridy = 3; p1.add(jHex5, c); c.gridx = 15; c.gridy = 6; p1.add(label6, c); c.gridx = 18; c.gridy = 6; p1.add(jHex6, c); c.gridx = 15; c.gridy = 9; p1.add(label7, c); c.gridx = 18; c.gridy = 9; p1.add(jHex7, c); c.weightx = 0.0; c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 15; c.gridy = 12; p1.add(jClear, c); // ****** EXIT Button ******* c.weightx = 0.0; c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 15; c.gridy = 15; p1.add(jExit, c); add(p1); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("Hex Puzzle"); setSize(800,600); setVisible(true); } public static void main (String[] args) { new test(); } }