Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
lowell seitz
631 PointsGUI Label Overwriting the One Before it
When I run this code only the last label is showing up on my panel. How do I show all the labels and not overwrite the one before it?
public HealthProfileGUI(String healthP) throws HeadlessException
{
super(healthP);
// TODO Auto-generated constructor stub
//set a default window size
this.setSize(500, 500);
// start the window visible
this.setVisible(true);
// default close operations
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
//set up the window controls
JLabel nameLabel = new JLabel("Enter Name: ");
this.getContentPane().add(nameLabel);
JLabel ageLabel = new JLabel("Enter Age: ");
this.getContentPane().add(nameLabel, ageLabel);
JLabel weightLabel = new JLabel("Enter Weight: ");
this.getContentPane().add(weightLabel);
JLabel heightFeetLabel = new JLabel("Enter Height in Feet: ");
this.getContentPane().add(heightFeetLabel);
JLabel heightInchesLabel = new JLabel("Enter Height in Inches: ");
this.getContentPane().add(heightInchesLabel);
}
Caleb Kleveter
Treehouse Moderator 37,862 PointsCaleb Kleveter
Treehouse Moderator 37,862 PointsHi, Lowell. I would like to help, but I am not fluent enough in Java and its APIs to know what is happening. I hope you find the answer to your problem!