Link to home
Start Free TrialLog in
Avatar of volavy
volavy

asked on

jTable in JBuilder

Hi!

I am somewhat a beginner in java programming and I have a question concerning managing jTables in JBuilder (v6).

Question:
A have lets say three string variables (s1, s2, s3) and I "simply" want to add this strings in a iterative way into different rows i a jTable on a button click. Like this:

jTable1:

Kolumn-name1  Kolumn-name2  Kolumn-name1
s11           s21           s31
s12           s22           s32
  ...and so on ...


Could someone help me with this?

Regards
/Peter
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

This is the principle involved. You, of course, would substitute TableModel's setValueAt():

public class SetTable {

  final static String[]  strings = { "a","b","c","d","e","f" };
  static int ROW_COUNT = 2;
  static int COL_COUNT = 3;

  public static void main(String[] args){
    int stringIndex = 0;
    for(int col = 0;col < COL_COUNT;col++){
      for(int row = 0;row < ROW_COUNT;row++){
        setValueAt(row,col,strings[stringIndex]);
        stringIndex++;
      }
    }
  }

  static void setValueAt(int row,int col,Object o){
    System.out.println("value at " + row + "," + col + " = " + (String)o);
  }

}
ASKER CERTIFIED SOLUTION
Avatar of Gidi Kern
Gidi Kern
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Incidentally, you've double-posted the question. I wonder if you could ask Community Support to delete it? https://www.experts-exchange.com/Community_Support/

I'll put a note in the duplicate to answer here.
for my first recommendation:
add your JTable instance to the JScrollPane.

-gkern
Avatar of volavy
volavy

ASKER

Thanks a lot
/Peter