Originariamente inviato da alka
Il codice si pubblica sul forum, non si comunica in privata, altrimenti la discussione non è utile a nessuno e nessun'altro può esserti d'aiuto.
Era solo per non riempire il post di codice!
codice:
        String Testo = TestoOriginale.getText();
        String TestoOriginale1 = Testo.replace(" ", "");
        
        int x = Chiave.getText().length();         
        int y = TestoOriginale1.length();
        int Nchar = 0;
        int ind =0;
        int righe = 0;
        int k = x + y;
        
        String totale = Chiave.getText() + TestoOriginale1;
        
        for (int NumeroRighe = 0 ; NumeroRighe < y ; NumeroRighe++)
        {
            int controllo = NumeroRighe * x;
            if (controllo >= y)
            {
                righe = NumeroRighe+1;
                break;
            }
        }
        
        	matrice1 = new JTextField[righe][x];
        	matrice2 = new JTextField[righe*x];
                tabella1.add(T3);

// matrice 1
		 
        for (int i = 0; i < righe; i++)
        {
            for (int j = 0; j < x; j++)
            {
                if (Nchar < k)
                {
                	matrice1[i][j] = new JTextField();
                	matrice1[i][j].setText (Character.toString(totale.charAt(Nchar)));
                	matrice1[i][j].setEditable(false);
                	matrice1[i][j].setHorizontalAlignment(javax.swing.JTextField.CENTER);
                
                Nchar++;
                
                if(i == 0)
                    matrice1[i][j].setBackground(Color.GREEN);
                }
                else 
                {
                	matrice1[i][j] = new JTextField();
                	matrice1[i][j].setText ("");
                	matrice1[i][j].setEditable(false);
                	matrice1[i][j].setHorizontalAlignment(javax.swing.JTextField.CENTER);
                
                	Nchar++;
                
               
                }
                
                tabella.setLayout(new GridLayout(righe,x));
                tabella.add(matrice1[i][j]);
            }
        }

        String s = Chiave.getText();
        char[] text = new char[s.length()];
        text = s.toCharArray();
        Arrays.sort(text);

        pannelloText.add(T4);
        
// Matrice 2

        for (int i = 0; i < x; i++)
        {
            String c1 = Character.toString(text[i]); 
        
            for (int n = 0; n < x; n ++) 
            {
                
                String c2 = Character.toString(s.charAt(n));
				s.replace (Character.toString(s.charAt(n)),".");
				System.out.println(s);
				
                    if(c1.equals(c2))
                    {
                    	for (int p = 1; p < righe; p++)
                        {
                        	if (!(matrice1[p][n].getText().equals("")))
                        	{
                        		matrice2[ind] = new JTextField();
                            	matrice2[ind].setText(matrice1[p][n].getText());
                            	matrice2[ind].setEditable(false);
                            	tabella1.add(matrice2[ind]);
							}
                            ind ++;
                        }
                    }    
            }
        }
        		getContentPane().add(tabella);
        		getContentPane().add(tabella1);
                        setSize(500,501);