Im trying to create a control array similar to what can be done in Visual Basic. I think this would be the way to go but i have hit a road block on the last lines of code. What i wanted to do was create a component array set to the size of what the JLayeredPane getComponentCountInLayer(int layer) method returns then get the actual components in the layer using JLayeredPanes getComponentsInLayer(int layer) method which is supposed to return a Component array. Then loop through the Component array and test each component in that array to see if they are an instance of a JTextComponent. Once that is done we can take the data validation from there. But the last two lines of code genterate incompatiable types errors.
Code:import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class DataForm {
public static void main(String[] args){
int height = 40;
int width = 100;
int space = 10;
int x = 0;
int y = 10;
JTextField[] jtc = new JTextField[9];
JLayeredPane jlp = new JLayeredPane();
JFrame jf = new JFrame("Data Form");
for(int i = 0; i < jtc.length; ++i){
jtc[i] = new JTextField();
}
for(int i = 0; i < jtc.length; ++i){
if(x == 0){
x = 10;
jtc[i].setBounds(new Rectangle(x, y, width, height));
jlp.add(jtc[i]);
continue;
}
x += (width + space);
jtc[i].setBounds(new Rectangle(x, y, width, height));
jlp.add(jtc[i]);
if(x > (jf.getWidth() - (width + space))){
x = 10;
y += (height + space);
jtc[i].setBounds(new Rectangle(x, y, width, height));
jlp.add(jtc[i]);
}
}
jf.setSize(500,400);
jf.setVisible(true);
Component comps = new Component[jlp.getComponentCountInLayer(jlp.highestLayer())];
comps = jlp.getComponentsInLayer(jlp.highestLayer());
}
}
