Hi, in einem Dialog hab ich 2 Tabellen (tblMitarbeiter, tblMeilenstein), die mit Daten aus einer Datenbankabfrage gefüllt werden. per Button füge ich in der Datenbank einen Eintrag hinzu und fülle die Tabellendaten neu ab und definiere die tabelle neu (zbs. tblMeilenstein = new JTable(this.rowDataMeilenstein, this.columnNamesMeilenstein); this.tblMeilenstein = tblMeilenstein)
, dies wird jedoch nicht angezeigt, nun möchte ich dies vereinfachen, und einfach eine Zeile an der Tabelle mit den Parametern hinzufügen. Wie kann ich bei der JTable eine Zeile hinzufügen?
code: package pendenz;
import java.awt.; import javax.swing.; import javax.swing.border.; import com.borland.jbcl.layout.; import java.awt.event.; import java.util.;
public class dlgDetail extends JDialog { DB DB = new DB(); JTable tblMitarbeiter = new JTable(); JTable tblMeilenstein = new JTable();
Object[][] Prioritat = {}; Object[][] Status = {}; Object[][] Kunde = {}; Object[][] Typ = {}; Object[][] Mitarbeiter = {};
String PendenzID = ""; String Bezeichnung = ""; String Start = ""; String Ende = ""; String Beschreibung = ""; String TypID = ""; String PrioritatID = ""; String GesAufwand = ""; String MaxAufwand = ""; String TatAufwand = ""; String KundeID = ""; String StatusID = "";
String[][] rowDataMeilenstein = {}; String columnNamesMeilenstein[] = { "Datum", "Meilenstein" };
String[][] rowDataMA = {}; String columnNamesMA[] = { "Name", "Vorname" }; JTextArea jTextAreaBeschreibung = new JTextArea(); Border border8; JButton jButtonDelete = new JButton();
public dlgDetail(Frame frame, String title, boolean modal) { super(frame, title, modal); try { jbInit(); pack(); } catch(Exception ex) { ex.printStackTrace(); } }
public dlgDetail() { this(null, "", false); }
public void setBox() { try { Typ = DB.GetData(1, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""); Prioritat = DB.GetData(2, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""); Status = DB.GetData(3, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""); Kunde = DB.GetData(4, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""); Mitarbeiter = DB.GetData(5, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "");
for(int r = 0; r < Mitarbeiter.length; r++) { jComboBoxMitarbeiter.addItem(new TextValuePair(Mitarbeiter[r][2].toString() + " " + Mitarbeiter[r][3].toString(), Mitarbeiter[r][0].toString())); }
for (int r = 0; r < Typ.length; r++) { jComboBoxTyp.addItem(new TextValuePair(Typ[r][1].toString(), Typ[r][0].toString())); }
for (int r = 0; r < Prioritat.length; r++) { jComboBoxPrioritat.addItem(new TextValuePair(Prioritat[r][1].toString(), Prioritat[r][0].toString())); }
for (int r = 0; r < Status.length; r++) { jComboBoxStatus.addItem(new TextValuePair(Status[r][1].toString(), Status[r][0].toString())); }
for (int r = 0; r < Kunde.length; r++) { jComboBoxKunde.addItem(new TextValuePair(Kunde[r][1].toString(), Kunde[r][0].toString())); } } catch(Exception ex) { ex.printStackTrace(); }
}
public void setDetail(String PendenzID) { try { Object[][] Detail = DB.GetData(6, "", "", "", "", "", "", "", "", "", "", "", PendenzID, "", "", "", "", "", "", "");
jTextFieldBezeichnung.setText(Detail[0][1].toString()); jTextFieldStartAm.setText(Detail[0][2].toString()); jTextFieldEndeAm.setText(Detail[0][3].toString()); jTextAreaBeschreibung.setText(Detail[0][4].toString()); jTextFieldGesAufwand.setText(Detail[0][7].toString()); jTextFieldMaxAufwand.setText(Detail[0][8].toString()); jTextFieldTatAufwand.setText(Detail[0][9].toString()); String Kunde = Detail[0][10].toString(); String Status = Detail[0][11].toString(); String Typ = Detail[0][5].toString(); String Prioritat = Detail[0][6].toString(); } catch(Exception ex) { ex.printStackTrace(); }
this.setTitle("Pendenz-Verwaltung | Details" + " " + this.PendenzID);
}
public void setTableMS(String PendenzID) { this.PendenzID = PendenzID; try {
Object[][] Meilenstein = DB.GetData(7, "", "", "", "", "", "", "", "", "", "", "", PendenzID, "", "", "", "", "", "", ""); String[][] rowDataMeilensteinC = new String[Meilenstein.length][Meilenstein[0].length];
for(int r = 0; r < Meilenstein.length; r++) { rowDataMeilensteinC[r][0] = Meilenstein[r][3].toString(); rowDataMeilensteinC[r][1] = Meilenstein[r][2].toString(); }
this.rowDataMeilenstein = rowDataMeilensteinC; }
catch(Exception ex) { ex.printStackTrace(); } tblMeilenstein = new JTable(this.rowDataMeilenstein, this.columnNamesMeilenstein); this.tblMeilenstein = tblMeilenstein;
panel1.add(this.tblMeilenstein, new XYConstraints(330, 165, 235, 45)); JScrollPane scrollPane2 = new JScrollPane( this.tblMeilenstein ); panel1.add(scrollPane2, new XYConstraints(330, 165, 235, 45)); }
public void setTableMA(String PendenzID) { this.PendenzID = PendenzID; try { Object[][] Mitarbeiter = DB.GetData(8, "", "", "", "", "", "", "", "", "", "", "", PendenzID, "", "", "", "", "", "", ""); String[][] rowDataMitarbeiterC = new String[Mitarbeiter.length][Mitarbeiter[0].length];
for(int r = 0; r < Mitarbeiter.length; r++) { rowDataMitarbeiterC[r][0] = Mitarbeiter[r][3].toString(); rowDataMitarbeiterC[r][1] = Mitarbeiter[r][4].toString(); }
this.rowDataMA = rowDataMitarbeiterC; } catch(Exception ex) { ex.printStackTrace(); } tblMitarbeiter = new JTable(this.rowDataMA, this.columnNamesMA); panel1.add(tblMitarbeiter, new XYConstraints(330, 355, 230, 70)); JScrollPane scrollPane = new JScrollPane( tblMitarbeiter ); panel1.add(scrollPane, new XYConstraints(330, 355, 230, 70)); }
void jButtonAbbrechen_actionPerformed(ActionEvent e) { this.hide(); }
void jButtonSpeichern_actionPerformed(ActionEvent e) { this.Bezeichnung = jTextFieldBezeichnung.getText(); this.Start = jTextFieldStartAm.getText(); this.Ende = jTextFieldEndeAm.getText(); this.Beschreibung = jTextAreaBeschreibung.getText(); this.TypID = ((TextValuePair)jComboBoxTyp.getSelectedItem()).value; this.PrioritatID = ((TextValuePair)jComboBoxPrioritat.getSelectedItem()).value; this.GesAufwand = jTextFieldGesAufwand.getText(); this.MaxAufwand = jTextFieldMaxAufwand.getText(); this.TatAufwand = jTextFieldTatAufwand.getText(); this.KundeID = ((TextValuePair)jComboBoxKunde.getSelectedItem()).value; this.StatusID = ((TextValuePair)jComboBoxStatus.getSelectedItem()).value; try { DB.SetData(9, this.TypID, this.Bezeichnung, this.Beschreibung, this.Start, this.Ende, this.GesAufwand, this.MaxAufwand, this.TatAufwand, this.PrioritatID, this.StatusID, this.KundeID, this.PendenzID, "", "", "", "", "", "", ""); } catch(Exception ex) { ex.printStackTrace(); } }
void jButtonDelete_actionPerformed(ActionEvent e) { try { DB.SetData(14, "", "", "", "", "", "", "", "", "", "", "", this.PendenzID, "", "", "", "", "", "", ""); DB.SetData(15, "", "", "", "", "", "", "", "", "", "", "", this.PendenzID, "", "", "", "", "", "", ""); DB.SetData(16, "", "", "", "", "", "", "", "", "", "", "", this.PendenzID, "", "", "", "", "", "", ""); } catch(Exception ex) { ex.printStackTrace(); } this.hide(); }
void jButtonHinzu_actionPerformed(ActionEvent e) { try { DB.SetData(12, "", "", "", "", "", "", "", "", "", "", "", this.PendenzID, jTextFieldMeilenstein.getText().toString(), jTextFieldDatum.getText().toString(), "", "", "", "", ""); jTextFieldDatum.setText(""); jTextFieldMeilenstein.setText(""); } catch (Exception ex) { ex.printStackTrace(); } setTableMS(this.PendenzID); } }
class dlgDetail_jButtonAbbrechen_actionAdapter implements java.awt.event.ActionListener { dlgDetail adaptee;
dlgDetail_jButtonAbbrechen_actionAdapter(dlgDetail adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButtonAbbrechen_actionPerformed(e); } }
final class TextValuePair { final String text; final String value;
TextValuePair(String text, String value) { this.text = text; this.value = value; } public String toString() { return this.text; } }
class dlgDetail_jButtonSpeichern_actionAdapter implements java.awt.event.ActionListener { dlgDetail adaptee;
dlgDetail_jButtonSpeichern_actionAdapter(dlgDetail adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButtonSpeichern_actionPerformed(e); } }
class dlgDetail_jButtonDelete_actionAdapter implements java.awt.event.ActionListener { dlgDetail adaptee;
dlgDetail_jButtonDelete_actionAdapter(dlgDetail adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButtonDelete_actionPerformed(e); } }
class dlgDetail_jButtonHinzu_actionAdapter implements java.awt.event.ActionListener { dlgDetail adaptee;
dlgDetail_jButtonHinzu_actionAdapter(dlgDetail adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButtonHinzu_actionPerformed(e); } }