I searched for a while but I cant find a solution for my problem.
I want to display the Values of an ArrayList in a JTable, i'm pretty new to this and cant fix the error.
package Statistik;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class Statistic {
private static ArrayList<String> rowA = new ArrayList();
private static ArrayList<String> rowB = new ArrayList();
private static ArrayList<String> rowC = new ArrayList();
private static ArrayList<String> titel = new ArrayList();
private static ArrayList<Object> table = new ArrayList();
public static void main(String[] args) {
titel.add("Name");
titel.add("Art der Bearbeitung");
titel.add("Datum");
addRows("buchung", "Created", "10.10.10");
addRows("buchung", "Created", "10.10.10");
addRows("buchung", "Created", "10.10.10");
addRows("buchung", "Created", "10.10.10");
addRows("buchung", "Created", "10.10.10");
table.add(rowA);
table.add(rowB);
table.add(rowC);
// Das JTable initialisieren
JTable EndTable = new JTable( table , titel );
JFrame frame = new JFrame( "Demo" );
frame.getContentPane().add(new JScrollPane( EndTable ) );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.pack();
frame.setVisible( true );
}
public static void addRows(String rowa, String rowb, String rowc) {
rowA.add(rowa);
rowB.add(rowb);
rowC.add(rowc);
}
}
I can't set the ArrayList
table
as first Value in my EndTable
, but i dont know how I should do otherwise.
Thank you all for trying to answer my problem.
Edit
My goal is to make a List with
Entity-Name, art of change, Date
so I thought it would be the best to use an ArrayList because it's flexible. It have to be flexible because we dont know how much the user will change.