java - Create a matrix using JTextFields or JTextAreas -


i have make program has able show matrix in form of jtextfields or jtextareas, user can write in them(a number of matrix each jtextfield). problem have no idea how create custom jpanel size , quantity of jtextfields user specifies(a different each time). have googled question, no avail.

take @ gridlayout. pretty simple put grid couple params (row , col count). paraphrase javadoc:

   public static void main (string[] args) {            jpanel panel = new jpanel();               panel.setlayout(new gridlayout(3,2));          panel.add(new jtextfield("1"));          panel.add(new jtextfield("2"));          panel.add(new jtextfield("3"));          panel.add(new jtextfield("4"));          panel.add(new jtextfield("5"));          panel.add(new jtextfield("6")); 

would result in 3 row 2 col grid of jtextfields

edit:

here more, in class named demo:

 public class demo {  public static void main(final string[] args) {     if (args.length < 2) {         system.out.print("please enter row , col on commandline");     }     swingutilities.invokelater(new runnable(){         public void run() {             new demo(integer.parseint(args[0]), integer.parseint(args[1]));          }     });  }   public demo(int colcnt, int rowcnt) {     jframe frame = new jframe("demo");     frame.setsize(600, 600);     jpanel panel = new jpanel();          panel.setlayout(new gridlayout(colcnt,rowcnt));      (int =0; < rowcnt*colcnt; i++) {        panel.add(new jtextfield(""+i));     }      frame.setcontentpane(panel);     frame.setdefaultcloseoperation(jframe.exit_on_close);     frame.setvisible(true); } } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -