Search code examples
javajformattedtextfield

Is it possible to create table of JFormattedTextField?


Is it possible to create table of JFormattedTextField?

JFormattedTextField field [][]  = new JFormattedTextField();
                    field.setBounds(0, 0, 50, 50); 
                    panel.add(field[2][2]);

And then field[2][2].getText()?


Solution

  • If you really want a 2 dimensional array containing 2500 JFormattedTextField then try:

    JFormattedTextField field [][] = new JFormattedTextField[50][50];
    
    for (int i=0;i<field.length;i++) {
       for (int j=0;j<field[i].length;j++) {
         field[i][j]=new JFormattedTextField();
       }
    }
    

    I doubt you really want that though...

    Read this: https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem