Guest User

Untitled

a guest
Feb 11th, 2019
62
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int val = (int) textFieldGen.getModel().getValue(); //getting the value from JSpinner
  2.  
  3. JTextField[] txtField = new JTextField[val];
  4.  
  5. //tried panel.revalidate(); panel.repaint();
  6.  
  7. //removing elements if exists. gives null pointer exception.
  8.  
  9. try {
  10. for (JTextField txtComp : txtField) {
  11. panel.remove(txtComp);
  12. }
  13. } catch (Exception ex) {
  14. System.out.println(ex);
  15. }
  16.  
  17. panel.revalidate();
  18. panel.repaint();
  19.  
  20.  
  21. //creating
  22. int row = 1;
  23. for (int i = 0; i < txtField.length; i++) {
  24. row++;
  25. layout.appendRow(RowSpec.decode("30px"));
  26. txtField[i] = new JTextField(10);
  27. panel.add(txt[i], cc.xy(4, row));
  28. }
  29. panel.revalidate();
  30. panel.repaint();
  31.  
  32. public JPanel createPanel(int numberOfTextFields) {
  33. JPanel panel=new JPanel(new ...);//create new panel
  34.  
  35. JTextField tfs[]=new JTextField[numberOfTextFields];//create array of textFields
  36.  
  37. for(int i=0;i<numberOfTextFields;i++) {
  38. tfs[i]=new JTextField();//create the textfield
  39. panel.add(tfs[i]...);//add it to the panel
  40. }
  41.  
  42. return panel;
  43. }
RAW Paste Data