ERLEDIGT
NEIN
NEIN
ANTWORTEN
8
8
ZUGRIFFE
5538
5538
EMPFEHLEN
-
30.05.06 17:00 #1
- Registriert seit
- May 2006
- Beiträge
- 19
Hallo Leute,
ich habe meine Daten so vorliegen dass ich den Standard Vector - Vector - Konstruktor zum aufbauen einer Tabelle benutzen kann.
nun bin ich vor dem Problem, dass meine Tabelle keinesfalls editierbar sein darf.
wie kann ich den Konstruktor Vector Vector in ein eigenes Table Modell übernehmen und wie mache ich dann beim aufbauen meiner Tabelle dann den Aufruf zum füllen der Tabelle.
Danke schonmal und Gruß
Malte Roessner
-
31.05.06 10:22 #2
- Registriert seit
- May 2006
- Beiträge
- 19
Hallo,
nunja ich würde ungerne n eigenes Table Modell nur für nicht Editierbarkeit der Zeilen schreiben müssen. vielleicht gehts ja auch anders?....
ich poste mal meinen Versuch eines eigenen TableModels, der allersings leider nicht funktioniert
Über response.getArray im Konstruktor bekomme ich meinen Tabellen Inhalt entsprechend im Vector von Vectoren Format... daher würde ich eigentlich gerne den Konstruktor table = new JTable(Vector, Vector) wenn schon ein TableModell nötig sein sollte gerne beibehalten...
wenn ich mit dem Modell arbeite bekomme ich eine leere Tabelle angezeigt...
Leider!
Danke an alle die mir bisher sehr weitergeholfen haben...
Gruß Malte
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
package ch.objeng.appl.eias.awf.worklet.ext.std.ORE; import javax.swing.JDialog; import javax.swing.JButton; import javax.swing.JTable; import javax.swing.JScrollPane; import javax.swing.table.*; import java.awt.event.*; import java.awt.BorderLayout; import java.util.Vector; /** * @author Malte Roessner * @version 0.1, 26.02.2006 * @since AWF 2.2.0 */ public class AuswahlGui extends JDialog implements ActionListener{ /* * The Construtor sets the common Data for the * folowing Dialog */ public AuswahlGui(Response response){ //allgemeine Daten des Dialoges festlegen this.setAlwaysOnTop(true); this.tableinhalt=response.getArray(); this.setLayout(null); this.setSize(450,250); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setLocation(((screenSize.width/2)-(this.getWidth()/2)),((screenSize.height/2))-(this.getHeight()/2)); this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); this.setTitle(" -- Vorschläge -- "); this.setResizable(false); this.setModal(true); } /** * the Actions are done here */ public void actionPerformed(ActionEvent event) { if( event.getSource() == ok_Button ){ if (table.getSelectedRow()!= -1){ int index = table.getSelectedRow(); reply = table.getValueAt(index ,0).toString(); }else { reply = table.getValueAt(0 ,0).toString(); } closeDialog(); } } /** * adds the Components to the Modal Dialog * a JTable and a JButton are added * for providing a choose if there are more than one result possible from the Engine * */ public void addComponenten(){ // add Components ok_Button = new JButton("OK"); ok_Button.setBounds(125,180,200,25); Vector tmp_vector = (Vector)(tableinhalt.elementAt(0)); //the names of the columns of the JTable are set here for (int i=0; i<tmp_vector.size(); i++){ spaltennamen.addElement(""+(i+1)+""); } //create JTable table = new JTable( tableinhalt, spaltennamen ); table.getTableHeader().setReorderingAllowed(false); //table = new JTable(new MeineTab()); scrollpane = new JScrollPane(table); scrollpane.setBounds(5,5,this.getWidth()-18,this.getHeight()/6*4); //add ActionListener to JButton ok_Button.addActionListener(this); //add Components to JDialog this.add(ok_Button); //this.add(ok_Button, BorderLayout.SOUTH); //this.add(scrollpane, BorderLayout.CENTER); this.add(scrollpane); this.setVisible(true); this.setEnabled(true); } /** * Methode is shouted * if everything is done to close the JDialog * */ public void closeDialog(){ this.setVisible(false); this.dispose(); } /* * Method to get the Chose of the Table for other using classes. * @return String reply chose of table row field 0,0 */ public String getReply(){ return reply; } ///****neuuuuuu class MeineTab extends DefaultTableModel{ Vector columnNames = spaltennamen; Vector data = tableinhalt; public boolean isCellEditable(int row, int col) { //Note that the data/cell address is constant, //no matter where the cell appears onscreen. return false; } } //******************* /* * Member Vars are set here */ Vector tableinhalt; Vector spaltennamen = new Vector(); JButton ok_Button; JScrollPane scrollpane; JTable table ; String reply; }
-
31.05.06 10:52 #3
Hallo Malte,
da Du ein eigenes TableModel nutzt, solltest Du diesem auch die beiden Vectoren übergeben:
damit das funktioniert, musst Du natürlich einen solchen Konstruktor in Dein TableModel implementieren:Code :1
MeineTab model = new MeineTab(tableinhalt, spaltennamen);
und dann mit diesem model die Tabelle erstellen:Code :1 2 3
public MyTableModel(Vector<Vector> data, Vector<String> columnNames) { super(data, columnNames); }
Code :1
JTable table = new JTable(model)
MfGIrren ist menschlich. Aber wer richtigen Mist bauen will, braucht einen Computer!
(unbekannt )
Bis irgendwann...
-
31.05.06 11:21 #4
- Registriert seit
- May 2006
- Beiträge
- 19
Hallo,
danke erstmal...
es klappt so weit die Editierbarkeit ist gesperrt.
nun habe ich allerdings das Problem, dass ich sie nicht mehr mit anklicken und ok_Button auslesen kann (Zeilenweise), ich benötige jeweils das erste Feld aus meiner Tabellenzeile die ausgewählt worden ist. Welche Methode muss ich in Model implementieren, dass auch das wieder klappt, es klappte vor Einbindung des Models.. geht das überhaupt mit DefaultTableModel.
Ich poste nochmal meinen abgeänderten Quelltext bei dem ich bei actionPerformed je das erste Feld aus der ausgewählten Tabellenzeile auswählen will.
Danke und Gruß
Euer
Malte
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
package ch.objeng.appl.eias.awf.worklet.ext.std.ORE; import javax.swing.JDialog; import javax.swing.JButton; import javax.swing.JTable; import javax.swing.JScrollPane; import javax.swing.table.*; import java.awt.event.*; import java.awt.BorderLayout; import java.util.Vector; /** * @author Malte Roessner * @version 0.1, 26.02.2006 * @since AWF 2.2.0 */ public class AuswahlGui extends JDialog implements ActionListener{ /* * The Construtor sets the common Data for the * folowing Dialog */ public AuswahlGui(Response response){ //allgemeine Daten des Dialoges festlegen this.setAlwaysOnTop(true); this.tableinhalt=response.getArray(); this.setLayout(null); this.setSize(450,250); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setLocation(((screenSize.width/2)-(this.getWidth()/2)),((screenSize.height/2))-(this.getHeight()/2)); this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); this.setTitle(" -- Vorschläge -- "); this.setResizable(false); this.setModal(true); } /** * the Actions are done here */ public void actionPerformed(ActionEvent event) { if( event.getSource() == ok_Button ){ if (table.getSelectedRow()!= -1){ int index = table.getSelectedRow(); reply = table.getValueAt(index ,0).toString(); }else { reply = table.getValueAt(0 ,0).toString(); } closeDialog(); } } /** * adds the Components to the Modal Dialog * a JTable and a JButton are added * for providing a choose if there are more than one result possible from the Engine * */ public void addComponenten(){ // add Components ok_Button = new JButton("OK"); ok_Button.setBounds(125,180,200,25); Vector tmp_vector = (Vector)(tableinhalt.elementAt(0)); //the names of the columns of the JTable are set here for (int i=0; i<tmp_vector.size(); i++){ spaltennamen.addElement(""+(i+1)+""); } //create JTable MeineTab model = new MeineTab(tableinhalt, spaltennamen); //table = new JTable( tableinhalt, spaltennamen ); JTable table = new JTable(model); table.getTableHeader().setReorderingAllowed(false); //table = new JTable(new MeineTab()); scrollpane = new JScrollPane(table); scrollpane.setBounds(5,5,this.getWidth()-18,this.getHeight()/6*4); //add ActionListener to JButton ok_Button.addActionListener(this); //add Components to JDialog this.add(ok_Button); //this.add(ok_Button, BorderLayout.SOUTH); //this.add(scrollpane, BorderLayout.CENTER); this.add(scrollpane); this.setVisible(true); this.setEnabled(true); } /** * Methode is shouted * if everything is done to close the JDialog * */ public void closeDialog(){ this.setVisible(false); this.dispose(); } /* * Method to get the Chose of the Table for other using classes. * @return String reply chose of table row field 0,0 */ public String getReply(){ return reply; } /** * * @author Admin * */ class MeineTab extends DefaultTableModel{ //Vector columnNames = spaltennamen; //Vector data = tableinhalt; public MeineTab(Vector data, Vector columnNames) { super(data, columnNames); } public boolean isCellEditable(int row, int col) { //Note that the data/cell address is constant, //no matter where the cell appears onscreen. return false; } } //******************* /* * Member Vars are set here */ Vector tableinhalt; Vector spaltennamen = new Vector(); JButton ok_Button; JScrollPane scrollpane; JTable table ; String reply; }
-
31.05.06 16:16 #5
- Registriert seit
- May 2006
- Beiträge
- 19
Hallo nochmal,
gehe ich recht in der Annahme, dass ich
public Object getValueAt(int row , int col) und
public int getSelectedRow()
in MeineTab erst überschreiben bzw mit neuem Leben füllen muss?
wenn ja kann mir jemand mal ne Seite sagen wo ein Beispiel dazu ist?
danke schonmal und Gruß
Malte
-
31.05.06 18:33 #6
Hallo,
mit getValueAt hast Du völlig recht. Hier ist mal ein kleines Beispiel, in dem eine Tabelle mit Daten gefüllt wird. Wenn Du nun eine Zelle anklickst und anschliessend den Button "auslesen" klickst, wird Dir der Inhalt der Zelle ausgegeben:
Hauptprogramm:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
package de.fhhst.tutorials; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Vector; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTable; public class TableModelSample extends JFrame { private static final long serialVersionUID = 1L; public static void main(String[] args) { new TableModelSample(); } public TableModelSample() { super("TableModelSample"); setDefaultCloseOperation(EXIT_ON_CLOSE); setLayout(null); setSize(350, 250); JButton button = new JButton("auslesen"); // Vector mit Spaltennamen anlegen Vector<String> colNames = new Vector<String>(); colNames.add("Spalte 1"); colNames.add("Spalte 2"); // Daten-Vector erstellen (Vorsicht Sinnfreiheit - nur zu Testzwecken) Vector<Vector> vData = new Vector<Vector>(); Vector<String> rowData; Integer value; for (int i = 1; i <= 10; i++) { rowData = new Vector<String>(); for (int j = 0; j < 2; j++) { value = new Integer((i + j) * (i + j)); rowData.add(value.toString()); } vData.add(rowData); } // eigenes TableModel mit Daten-Vector und Spaltennamen instanzieren MyTableModel model = new MyTableModel(vData, colNames); // Tabelle mit eigenem TableModel erstellen final JTable table = new JTable(model); add(table).setBounds(10, 10, 250, 180); add(button).setBounds(10, 200, 120, 20); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.out.println(table.getValueAt(table.getSelectedRow(), table.getSelectedColumn())); } }); setVisible(true); } }
TableModel:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
package de.fhhst.tutorials; import java.util.Vector; import javax.swing.table.DefaultTableModel; public class MyTableModel extends DefaultTableModel { private Vector<Vector> dataVector = new Vector<Vector>(); private static final long serialVersionUID = 1L; public MyTableModel(Vector<Vector> data, Vector<String> columnNames) { super(data, columnNames); setDataVector(data); } public boolean isCellEditable(int row, int col) { return false; } public Object getValueAt(int row, int col) { return getDataVector().get(row).get(col); } public Vector<Vector> getDataVector() { return dataVector; } public void setDataVector(Vector<Vector> dataVector) { this.dataVector = dataVector; } }
Da solltest Du die Antworten zu Deinen gestellten Fragen finden.
MfGIrren ist menschlich. Aber wer richtigen Mist bauen will, braucht einen Computer!
(unbekannt )
Bis irgendwann...
-
01.06.06 23:13 #7
- Registriert seit
- May 2006
- Beiträge
- 19
Hallo,
danke erstmal für die ausführliche Anwort mit dem Tablemodell.
also meine Übergabe läuft ohne Modell (1) einwandfrei allerdings mit Modell (2) schmiert er schon beim Aufbauen der Tabelle mit folgender Fehlermeldung ab...
wenn du vielleicht meinen Tippfehler oder sonstigen Tippfehler entdecken würdest wäre das phänomenal
danke erstmal und Gruß
Malte
PS: gleiche Art aufzurufen läuft bei deiner Testklasse "TableModelSample"
mit den Zeilen:
einwandfrei. ich weiss nicht was ich bei meinem Aufruf anders mache ...Code :1 2 3 4 5 6 7 8 9 10
// eigenes TableModel mit Daten-Vector und Spaltennamen instanzieren MyTableModel model = new MyTableModel(vData, colNames); // Tabelle mit eigenem TableModel erstellen final JTable table = new JTable(model); JScrollPane scrollpane = new JScrollPane(table); add(scrollpane).setBounds(10, 10, 250, 180); add(button).setBounds(10, 200, 120, 20);
Exception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException: 2 >= 2
at java.util.Vector.elementAt(Unknown Source)
at ch.objeng.appl.eias.awf.worklet.ext.std.ORE.MyTableModel.getValueAt(MyTableModel.java:23)
at javax.swing.JTable.getValueAt(Unknown Source)
at javax.swing.JTable.prepareRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JViewport.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException: 2 >= 2
at java.util.Vector.elementAt(Unknown Source)
at ch.objeng.appl.eias.awf.worklet.ext.std.ORE.MyTableModel.getValueAt(MyTableModel.java:23)
at javax.swing.JTable.getValueAt(Unknown Source)
at javax.swing.JTable.prepareRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JViewport.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
at java.awt.Container.paint(Unknown Source)
at sun.awt.RepaintArea.paintComponent(Unknown Source)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException: 2 >= 2
at java.util.Vector.elementAt(Unknown Source)
at ch.objeng.appl.eias.awf.worklet.ext.std.ORE.MyTableModel.getValueAt(MyTableModel.java:23)
at javax.swing.JTable.getValueAt(Unknown Source)
at javax.swing.JTable.prepareRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JViewport.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException: 2 >= 2
at java.util.Vector.elementAt(Unknown Source)
at ch.objeng.appl.eias.awf.worklet.ext.std.ORE.MyTableModel.getValueAt(MyTableModel.java:23)
at javax.swing.JTable.getValueAt(Unknown Source)
at javax.swing.JTable.prepareRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JViewport.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
package ch.objeng.appl.eias.awf.worklet.ext.std.ORE; import javax.swing.JDialog; import javax.swing.JButton; import javax.swing.JTable; import javax.swing.JScrollPane; import javax.swing.table.*; import java.awt.event.*; import java.util.Vector; /** * @author Malte Roessner * @version 0.1, 26.02.2006 * @since AWF 2.2.0 */ public class AuswahlGui extends JDialog implements ActionListener{ /* * The Construtor sets the common Data for the * folowing Dialog */ public AuswahlGui(Response response){ //allgemeine Daten des Dialoges festlegen this.setAlwaysOnTop(true); this.tableinhalt=response.getArray(); this.setLayout(null); this.setSize(450,250); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setLocation(((screenSize.width/2)-(this.getWidth()/2)),((screenSize.height/2))-(this.getHeight()/2)); //this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); this.setTitle(" -- Vorschläge -- "); this.setResizable(false); this.setModal(true); addComponenten(); } /** * the Actions are done here */ public void actionPerformed(ActionEvent event) { if( event.getSource() == ok_Button ){ if (table.getSelectedRow()!= -1){ int index = table.getSelectedRow(); reply = table.getValueAt(index ,0).toString(); }else { reply = table.getValueAt(0 ,0).toString(); } closeDialog(); } } /** * adds the Components to the Modal Dialog * a JTable and a JButton are added * for providing a choose if there are more than one result possible from the Engine * */ public void addComponenten(){ // add Components ok_Button = new JButton("OK"); ok_Button.setBounds(125,180,200,25); Vector tmp_vector = (Vector)(tableinhalt.elementAt(0)); //the names of the columns of the JTable are set here for (int i=0; i<tmp_vector.size(); i++){ spaltennamen.addElement(""+(i+1)+""); } //das funktioniert einwandfrei also ohne Modell (1) //table = new JTable(tableinhalt, spaltennamen); //scrollpane = new JScrollPane(table); //scrollpane.setBounds(5,5,this.getWidth()-18,this.getHeight()/6*4); //Abschmieren bei Table aufbauen (2) MyTableModel model = new MyTableModel(tableinhalt, spaltennamen); // Tabelle mit eigenem TableModel erstellen table = new JTable(model); JScrollPane scrollpane = new JScrollPane(table); scrollpane.setBounds(5,5,this.getWidth()-18,this.getHeight()/6*4); ok_Button.addActionListener(this); //add Components to JDialog this.add(scrollpane); this.add(ok_Button); this.setVisible(true); this.setEnabled(true); } /** * Methode is shouted * if everything is done to close the JDialog * */ public void closeDialog(){ this.setVisible(false); this.dispose(); } /** * Method to get the Chose of the Table for other using classes. * @return String reply chose of table row field 0,0 */ public String getReply(){ return reply; } /** * Member Vars are set here */ Vector tableinhalt ; Vector spaltennamen = new Vector(); JButton ok_Button; JScrollPane scrollpane; JTable table; String reply; }Geändert von Malte Roessner (01.06.06 um 23:16 Uhr) Grund: Anmerkung vergessen
-
02.06.06 11:48 #8
Ich denke, es wird daran liegen, wie Du den Datenvector erstellst:
Code :1
this.tableinhalt=response.getArray();
Ich kenne ja Dein Response-Object nicht. Wenn ich nun also den Datenvector mit dummy-daten fülle, klappt das wunderbar...
MfGIrren ist menschlich. Aber wer richtigen Mist bauen will, braucht einen Computer!
(unbekannt )
Bis irgendwann...
-
02.06.06 12:31 #9
- Registriert seit
- May 2006
- Beiträge
- 19
Hallo nochmal,
das seltsame ist nur dass es ja klappt mit meinem MiniModel und mit dem Standard-Vector-Vector-Konstruktor von Table. Ich poste dir mal eben meine
Response Klasse vielleicht findest ja was...
response.getArray() gibt n Vector von Vectoren zurück wie es im Konstruktor von JTable gefordert ist
aber nun der Code und Danke schon mal bis hierhin
Gruß Malte
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
import java.util.Vector; /** * @author Malte Roessner * @version 0.1, * Class Response to hold the Response of the * Rule Engine in a table-similar Datastructure */ public class Response { public Response() { d_currZeile=new Vector(); d_array=new Vector(); } /** * Adds an element to one row. * * @param element Object Element to be put into a table row * */ public void addElementToZeile(Object element) { d_currZeile.add(element); } /** * Adds a full row to the Table * */ public void copyZeileToArray() { d_array.add(d_currZeile); d_currZeile=new Vector(); } /** * Method returns the Data of one Row of the Table * @return Vector d_array Tablerow */ public Vector getArray() { return d_array; } //Member Vars /** * Vector defining current row of table */ private Vector d_currZeile; /** * Vector defining the table itself */ private Vector d_array; }
Ähnliche Themen
-
JTable: insertElementAt() bei einem generischen Vector
Von rob-master im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 3Letzter Beitrag: 22.05.08, 10:41 -
JTable aus Vector füllen
Von tameck im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 3Letzter Beitrag: 14.04.08, 11:03 -
Txt, später dann csv File in JTable einlesen(Idee Vector)
Von runT im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 8Letzter Beitrag: 16.08.07, 17:55 -
Vector in Vector geht nicht
Von TimN im Forum C/C++Antworten: 3Letzter Beitrag: 10.05.07, 19:19 -
Vector als Spalte in einer JTable anzeigen
Von Sharam im Forum JavaAntworten: 2Letzter Beitrag: 02.05.06, 00:34





Zitieren
Login





