I am trying to create a Java 7 address book using Eclipse and when I test run the JFrame, JLabels aren’t visible and JButtons overlap. (Buttons will take up the whole JFrame)
For example
add(saveButton);
add(cancelButton);
add(headingLabel);
headingLabel.setVisible(true);
cancelButton.setLocation(200,200);
saveButton.setLocation(400,200);
cancelButton.setSize(200,50);
saveButton.setSize(200,50);
What am I doing wrong?
You should use a LayoutManager instead of absolute coordinates. Using Layout managers, you don’t have to care so much about the exact positions of your GUI elements. The layout is done for you.
Check out the Visual Guide to Layout Managers. It explains the most common layout types with visual and code examples.