I'm fairly new to Java, and I've been playing around with Swing. I put two JPanels into a JFrame, which apparantly align themselves side-by-side by default. I then created two text boxes and put them into the left panel and the right panel respectively. The first text box shows up as expected. The text box in the right panel, however, 'hides' under the left panel, and in order to get it to appear fully on the right panel I have to maximize the window. I did some other testing with this, and if I draw on the right panel (using the Graphics class) at the origin it appears in the upper left corner of the window (on the left panel).
Here's the code I'm using:
import javax.swing.*;
import java.awt.*;
public class test {
public static void main(String[] args) {
JFrame frame = new JFrame();
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
p1.setSize(500, 500);
p2.setSize(200, 500);
frame.setSize(700, 500);
JLabel ltext = new JLabel("Left Panel Text");
JLabel rtext = new JLabel("Right Panel Text");
p1.add(ltext);
p2.add(rtext);
frame.getContentPane().add(p1);
frame.getContentPane().add(p2);
frame.show();
}
}
Is this how panels are supposed to act -- not putting things on their own visible area -- or am I doing something wrong (probably more likely)?