Hi, was wondering if anyone could help me. I'm creating my own little simple tree structure, consisting of several JTextFields. Each TextField is added to a JPanel, which is finally added to a JScrollPane, which is then added to a JFrame. Everything is fine, apart from the position of the JTextFields. Within the for loop below, I try to position them (so one is below the other), but when I run the program it puts them side by side - no matter what I do in that for loop, I cannot change the position of those TextFields within that JPanel - can someone help me?
public JScrollPane drawTree(){
int pos = 20;
JScrollPane scroll = new JScrollPane();
scroll.setBounds(584, 71, 600, 600);
//scroll.setLayout(null);
JPanel p = new JPanel();
for (int i = ((left.length)-1); i>(-1); i--){
if (!(left[i].equals(""))){
JTextField x = new JTextField(left[i]);
x.setEditable(false);
// TRY TO POSITION THE TEXT FIELD
if ((right[0].equals("")) && (centre[0].equals(""))){
x.setLocation(180, pos);
//x.setAlignmentX(180);
//x.setAlignmentY(pos);
//x.setLocation((p.getX()+180), (p.getY()+pos));
//x.setSize(140, 30);
//x.setBounds(180, pos, 140, 30);
}
x.setHorizontalAlignment(JTextField.CENTER);
p.add(x);
//x.invalidate();
//x.validate();
//x.repaint();
pos += 100;
}
}
p.setBackground(Color.WHITE);
//testPanel(p);
scroll.setViewportView(p);
return scroll;
// SCROLL IS LATER ADDED TO A JFRAME
}