Guten Tag zusammen! Ich habe ein Problem mit meiner JTable. Ich will eine Tabelle, welche aus einem Vector besteht, auf dem GUI ausgeben lassen. Die header werden angezeigt, nur die einträge selber erscheinen nicht. Was mache ich genau falsch? Hier der Code des GUIs:
Und hier noch die Klasse "TableAdapter":
Vielen Dank schon mal im Voraus!
Java:
public class TableGUI extends TemplateGUI implements ActionListener {
private static final String CSV_CONVERTER_STEP_2_OF_4_CHECK_ENTRIES = "CSV-Converter Step 2 of 4: Check Entries";
private static final long serialVersionUID = 1L;
private JLabel lbl_desc;
private JTable tbl_content;
private JScrollPane scb;
public TableGUI() {
super(CSV_CONVERTER_STEP_2_OF_4_CHECK_ENTRIES);
Vector<Article> dataVector = new Vector<Article>();
Container c = getContentPane();
setSize(650, 500);
// Label für die Beschreibung
lbl_desc = new JLabel("<html>Now, please fill in the Types for each Entry in the Table and click next.</html>");
lbl_desc.setBounds(142, -100, 250, 300);
c.add(lbl_desc);
pic1.setBounds(570, 15, 65, 65);
// Next-Button
btn_next.addActionListener(this);
// Back-Button
btn_back.addActionListener(this);
// Cancel-Button
btn_cancel.addActionListener(this);
// Tabelle für den Inhalt
TableAdapter adapter = new TableAdapter(dataVector);
tbl_content = new JTable(adapter);
tbl_content.setRowHeight(30);
c.add(tbl_content);
// Scrollbar
scb = new JScrollPane(tbl_content);
scb.setBounds(10, 100, 600, 240);
scb.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scb.setViewportView(tbl_content);
c.add(scb);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Cancel")) {
System.exit(0);
} else if (e.getActionCommand().equals("Back")) {
new ImportGUI();
this.dispose();
} else if (e.getActionCommand().equals("Next")) {
new ExportGUI();
this.dispose();
}
}
public Vector<Article> createDataVector() {
Vector<Article> dataVector = new Vector<Article>();
Article article1 = new Article("2345", "011", "Artikel 1", articleType.zonebased);
Article article2 = new Article("3456", "230", "Artikel 2", articleType.fixprice);
Article article3 = new Article("4567", "152", "Artikel 3", articleType.zonebased);
Article article4 = new Article("6789", "022", "Artikel 4", articleType.relationbased);
Article article5 = new Article("5678", "011", "Artikel 5", articleType.relationbased);
dataVector.add(article1);
dataVector.add(article2);
dataVector.add(article3);
dataVector.add(article4);
dataVector.add(article5);
return dataVector;
}
}
Und hier noch die Klasse "TableAdapter":
Java:
public class TableAdapter implements TableModel {
private Vector<Article> dataVector;
public TableAdapter(Vector<Article> dataVector) {
super();
this.setDataVector(dataVector);
}
public void addTableModelListener(TableModelListener l) {
// TODO Auto-generated method stub
}
public Class<?> getColumnClass(int columnIndex) {
return String.class;
}
public int getColumnCount() {
// TODO Auto-generated method stub
return 4;
}
public String getColumnName(int columnIndex) {
// TODO Auto-generated method stub
switch (columnIndex) {
case (0):
return "ID";
case (1):
return "Tariffcode";
case (2):
return "Name";
case (3):
return "ArticleType";
default:
return "Index nicht gefunden!";
}
}
public Vector<Article> getDataVector() {
return dataVector;
}
public int getRowCount() {
return dataVector.size();
}
public Object getValueAt(int rowIndex, int columnIndex) {
switch (columnIndex) {
case (0):
return;
}
return null;
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
if (columnIndex == 3) {
return true;
} else {
return false;
}
}
public void removeTableModelListener(TableModelListener l) {
// TODO Auto-generated method stub
}
public void setDataVector(Vector<Article> dataVector) {
this.dataVector = dataVector;
}
public void setValueAt(Object value, int rowIndex, int columnIndex) {
// TODO Auto-generated method stub
}
}
Vielen Dank schon mal im Voraus!