Swing jTable und AbstractTableModel

kneubi

Mitglied
Hallo zusammen

Vorabinformation:
Ich nutze Eclipse Indigo und programmiere mit jre/jdk1.6 auf einem MacbookPro. Im Eclipse habe ich das Plugin Jigloo integriert welches mir bei meinen anfänglichen GUI-Schritten sehr hilft... gemäss Internet läuft es mit Swing/SWT.

Nun zum Problem:

Ich kämpfe nun schon seit gut drei Tagen mit meinem Javaprogramm... es hat alles soweit wie gewollt funktioniert. Nun ist mir aber die Idee gekommen im "HauptGUI" könnte ich eigentlich auch noch eine jTable erstellen anstatt eine jList, also habe ich die jList ausgetauscht und fleissig angefangen überall den Code anzupassen... die jTable in dieser Form verwende ich bereits bei einem weiteren Fenster das zusätzlich aufgerufen wird, allerdings habe ich beim Aufbauen des GUIs kein Problem da ich dort bereits Daten mitgeben kann. Auf dem HauptGUI kann ich dies aber nicht. Die jTables werden mit einer eigenen Klasse gefüttert die das AbstractTableModel extended.

Und im Voraus entschuldigt bitte den seeeeeeeeehr schlechten Code im Auge eines professionellen Programmierers.. ich habe vor 2 Monaten mit Java wieder angefangen, hatte davor etwas Erfahrung mit Programmieren mit VB.NET und habe einen 3 Tage Crashkurs Java hinter mir. Der Code ist entstanden aus Ideen, Java-lern-ebooks lesen und im Internet nachschlagen wie man es lösen könnte.

Hier erstmal der Code:
Ich habe 2 Packages:

_____Package1: Daten_____
Class: Army
Java:
package Daten;

import java.util.ArrayList;

public class Army {
	public String strArmyName;
	public Boolean bolFlying = false;
	public Boolean bolMechanized = false;
	public Boolean bolTired = false;
	public Boolean bolFortified = false;
	public Boolean bolVigliant = false;
	public Boolean bolAntiScouting = false;
	public Boolean bolUnderArtilleryFire = false;
	public Boolean bolWithoutHQ = false;
	public Integer intArmyPointCosts;
	public Integer intArmyMovment;
	public Integer intArmySight;
	public ArrayList<Unit> alUnit = new ArrayList<Unit>();
	
	public Army(){
		
	}
	
	public Army(String newArmy){
		strArmyName = newArmy;
	}
	
	public String toString(){
		return strArmyName;
	}
	
	public void addUnit(String UnitAdd){
//		Integer i;
		Unit objUnit = new Unit(UnitAdd);
		alUnit.add(objUnit);
//		Object ai[] = alUnit.toArray();
//		for (i = 0; i < ai.length; i++){
//			System.out.println(ai[i]);
//		}
	}

	public Boolean getBolFlying() {
		return bolFlying;
	}

	public void setBolFlying(Boolean bolFlying) {
		this.bolFlying = bolFlying;
	}

	public Boolean getBolMechanized() {
		return bolMechanized;
	}

	public void setBolMechanized(Boolean bolMechanized) {
		this.bolMechanized = bolMechanized;
	}

	public Boolean getBolTired() {
		return bolTired;
	}

	public void setBolTired(Boolean bolTired) {
		this.bolTired = bolTired;
	}

	public Boolean getBolFortified() {
		return bolFortified;
	}

	public void setBolFortified(Boolean bolFortified) {
		this.bolFortified = bolFortified;
	}

	public Boolean getBolVigliant() {
		return bolVigliant;
	}

	public void setBolVigliant(Boolean bolVigliant) {
		this.bolVigliant = bolVigliant;
	}

	public Boolean getBolAntiScouting() {
		return bolAntiScouting;
	}

	public void setBolAntiScouting(Boolean antiScouting) {
		bolAntiScouting = antiScouting;
	}

	public Boolean getBolUnderArtilleryFire() {
		return bolUnderArtilleryFire;
	}

	public void setBolUnderArtilleryFire(Boolean bolUnderArtilleryFire) {
		this.bolUnderArtilleryFire = bolUnderArtilleryFire;
	}

	public Boolean getBolWithoutHQ() {
		return bolWithoutHQ;
	}

	public void setBolWithoutHQ(Boolean bolWithoutHQ) {
		this.bolWithoutHQ = bolWithoutHQ;
	}	

}

Class: Equipment
Java:
package Daten;


public class Equipment {
	public String strEquipmentName;
	public Integer intEquipmentPointCosts;
	
	public Equipment(String newUnit){
		strEquipmentName = newUnit;
	}
	
	public Equipment(String newUnit, Integer newEquipmentCosts){
		strEquipmentName = newUnit;
		intEquipmentPointCosts = newEquipmentCosts;
	}

	public String getStrEquipmentName() {
		return strEquipmentName;
	}

	public void setStrEquipmentName(String strEquipmentName) {
		this.strEquipmentName = strEquipmentName;
	}

	public Integer getIntEquipmentPointCosts() {
		return intEquipmentPointCosts;
	}

	public void setIntEquipmentPointCosts(Integer intEquipmentPointCosts) {
		this.intEquipmentPointCosts = intEquipmentPointCosts;
	}
	
	
}

Class: MyTableModel
Java:
package Daten;

import java.util.List;
import javax.swing.table.AbstractTableModel;
 
/**
 *
 * @author sash
 */
public class MyTableModel extends AbstractTableModel{
 
    private static final String[] HEADER = {"Slot", "Unitname", "Points", "Flying", "Mechanized", "Equipment"};
    private List<Unit> data;
    public Integer IntDataSize;

    public MyTableModel() {

    }
    
    public MyTableModel(List<Unit> data) {
        this.data = data;
    }
 
 
 
    public int getRowCount() {
    		return data.size();
    }
 
    public int getColumnCount() {
        return HEADER.length;
    }
 
    public Object getValueAt(int row, int column) {
        Unit unit = data.get(row);
 
        switch(column){
            case 0: return unit.getStrSlot();
            case 1: return unit.getStrUnitName();
            case 2: return unit.getIntPointCosts();
            case 3: return unit.getBolFlying();
            case 4: return unit.getBolMechanized();
            default: return "";
        }
    }
 
    @Override
    public String getColumnName(int column) {
        return HEADER[column];
    }
 
// Hier kann man die Klasse für eine Spalte ändern. 
    @Override
    public Class<?> getColumnClass(int column) {
        if(column == 3){
            return Boolean.class;
        }
        if(column == 4){
            return Boolean.class;
        }
        if(column == 5){
            return Boolean.class;
        }
        return super.getColumnClass(column);
    }
 
 
}

Class: Player
Java:
package Daten;

import java.util.ArrayList;


public class Player {
	public String strPlayerName;
	public String strFelderory[];
	public String strArmysory[];
	public int intIAP;
	public String strIAPHistory[];
	public int intTAP;
	public String strTAPHistory[];
	public int intKP;
	public String strKPHistory[];
	public int intSP;
	public String strSPHistory[];
	public int intSTP;
	public String strSTPHistory[];
	public ArrayList<Army> alArmy = new ArrayList<Army>();
	
	public Player() {
	}
	
	public Player(String newPlayer) {
		strPlayerName = newPlayer;
	}
	
	public String getStrPlayerName() {
		return strPlayerName;
	}

	public void setStrPlayerName(String strPlayerName) {
		this.strPlayerName = strPlayerName;
	}

	public int getIntIAP() {
		return intIAP;
	}

	public void setIntIAP(int intIAP) {
		this.intIAP = intIAP;
	}

	public int getIntTAP() {
		return intTAP;
	}

	public void setIntTAP(int intTAP) {
		this.intTAP = intTAP;
	}

	public int getIntKP() {
		return intKP;
	}

	public void setIntKP(int intKP) {
		this.intKP = intKP;
	}

	public int getIntSP() {
		return intSP;
	}

	public void setIntSP(int intSP) {
		this.intSP = intSP;
	}

	public int getIntSTP() {
		return intSTP;
	}

	public void setIntSTP(int intSTP) {
		this.intSTP = intSTP;
	}

	public String toString() {
		return strPlayerName;
	}
	
	public void addArmy(String ArmyAdd){
		Army objArmy = new Army(ArmyAdd);
		alArmy.add(objArmy);
	}
	
	public void deleteAllArmys(){
		Integer i;
		for (i = 0; i < alArmy.toArray().length; i++) {
			alArmy.remove(i);
		}
			
	}
	
	public void deleteOneArmy(Object y){
			alArmy.remove(y);
			
	}
}

Class: Unit
Java:
package Daten;


public class Unit {


	public String strUnitName;
	public Integer intPointCosts = 0;
	public Boolean bolFlying = false;
	public Boolean bolMechanized = false;
	public String strSlot;
	public String strAllInfo;
	public Integer intBasicPointCosts = 0;
	public Integer intEquipmentCosts = 0;
	
    

	public Unit(String newUnit){
		strUnitName = newUnit;
	}
	
	public Unit(String newUnit, String newUnitSlotObject, Integer newUnitCosts){
		strUnitName = newUnit;
		intPointCosts = newUnitCosts;
		strSlot = newUnitSlotObject.toString();
	}
	
	public Unit(String newUnit, String newUnitSlotObject, Integer newUnitCosts, Boolean newBolFlying, Boolean newBolMechanized){
		strUnitName = newUnit;
		intBasicPointCosts = newUnitCosts;
		strSlot = newUnitSlotObject.toString();
		bolFlying = newBolFlying;
		bolMechanized = newBolMechanized;
		intPointCosts = intBasicPointCosts + intEquipmentCosts;
	}
	
	public String toString(){
		return strUnitName;
	}
	
	public String toStringAll(){
		strAllInfo = strSlot + "--" + strUnitName + "--" + intPointCosts + "-- Flying " + bolFlying + "-- Mechanized " + bolMechanized;
		return strAllInfo;
	}
	
	public Boolean getBolFlying() {
		return bolFlying;
	}

	public void setBolFlying(Boolean bolFlying) {
		this.bolFlying = bolFlying;
	}

	public Boolean getBolMechanized() {
		return bolMechanized;
	}

	public void setBolMechanized(Boolean bolMechanized) {
		this.bolMechanized = bolMechanized;
	}

	public String getStrSlot() {
		return strSlot;
	}

	public void setStrSlot(String strSlot) {
		this.strSlot = strSlot;
	}

	public String getStrUnitName() {
		return strUnitName;
	}
	
	public void setStrUnitName(String strUnitName) {
		this.strUnitName = strUnitName;
	}
	
	public Integer getIntPointCosts() {
		return intPointCosts;
	}

	public void setIntPointCosts(Integer intPointCosts) {
		this.intPointCosts = intPointCosts;
	}
	
	public Integer getIntBasicPointCosts() {
		return intBasicPointCosts;
	}

	public void setIntBasicPointCosts(Integer intBasicPointCosts) {
		this.intBasicPointCosts = intBasicPointCosts;
	}

	public Integer getIntEquipmentCosts() {
		return intEquipmentCosts;
	}

	public void setIntEquipmentCosts(Integer intEquipmentCosts) {
		this.intEquipmentCosts = intEquipmentCosts;
	}

}



Beim starten des MainGUI's erscheint nun die Fehlermeldung dass er mir die getRowCount() von meinem MyTableModel nicht aufrufen kann, ist ja eigentlich auch logich weil die Liste im Instanzierten Model leer ist. Aber ich habe keine Daten hier zu übergeben, ich habe bereits mit IF-Abfragen versucht alles abzufangen und ein Returnwert von "0" zu geben bei getRowCount() aber da hat es ebenso ein Fehler gespuckt... Gibts eine elegantere Lösung?

Ich will beim Aufbauen des GUIs einfach eine jTable mit den Spaltenüberschriften aber noch keine Daten darin, doch wie kriege ich das mit einem AbstractTableModel hin?

Gruss
Kneubi
 
Zuletzt bearbeitet:
____Package2: GUI____

Class:MainGUI ------- Teil1
Java:
package GUI;
import java.awt.event.*;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListModel;
import java.util.*;

import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle;

import Daten.MyTableModel;
import Daten.Player;
import Daten.Unit;
import GUI.UnitAddGUI;

import javax.swing.SwingUtilities;


public class MainGUI extends javax.swing.JFrame implements ActionListener{

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	public JTextField jtxtPlayerAdd;
	public JButton jcmdPlayerAdd;
	public ArrayList<Player> alPlayer = new ArrayList<Player>();
	public JComboBox jcbPlayer;
	public JButton jcmdArmyAdd;
	public static JTextField jtxtArmyAdd;
    private JCheckBox jchbFlying;
    private JTable jtblArmyView;
    private JButton jcmdUnitAdd;
    private JPanel jpArmyAttribues;
    private JScrollPane jspArmyView;
    private JButton jcmdPlayerRemove;
    private JButton jcmdArmyMerge;
    private JComboBox jcbPlayerArmyList2;
    private JCheckBox jchbWithoutHQ;
    private JCheckBox jchbUnderArtilleryFire;
    private JCheckBox jchbAntiScouting;
    private JCheckBox jchbMechanized;
    private JButton jcmdArmyRemove;
    private JCheckBox jchbTired;
    private JCheckBox jchbVigliant;
    private JCheckBox jchbFortified;
    private JComboBox jcbPlayerArmyList;
    public Integer intSelectedPlayer;
    public Integer intSelectedArmy;
    public ArrayList<DefaultListModel> alListModel = new ArrayList<DefaultListModel>();
    public ArrayList<MyTableModel> alMainGUITableModel = new ArrayList<MyTableModel>();
    

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				MainGUI inst = new MainGUI();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public MainGUI() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)getContentPane());
			getContentPane().setLayout(thisLayout);
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			//Textbox
			{
				jtxtPlayerAdd = new JTextField();
			}
			{
				jtxtArmyAdd = new JTextField();
			}
			
			//Button
			{
				jcmdPlayerAdd = new JButton();
				jcmdPlayerAdd.setText("Add Player");
				jcmdPlayerAdd.addActionListener(this);
			}
			{
				jcmdPlayerRemove = new JButton();
				jcmdPlayerRemove.setText("Remove Player");
				jcmdPlayerRemove.addActionListener(this);
			}
			{
				jcmdArmyAdd = new JButton();
				jcmdArmyAdd.setText("Add Army");
				jcmdArmyAdd.addActionListener(this);
			}
			{
				jcmdArmyRemove = new JButton();
				jcmdArmyRemove.setText("Remove Army");
				jcmdArmyRemove.addActionListener(this);
			}
			{
				jcmdArmyMerge = new JButton();
				jcmdArmyMerge.setText("Merge Army with");
				jcmdArmyMerge.addActionListener(this);
			}
			{
				jcmdUnitAdd = new JButton();
				jcmdUnitAdd.setText("Add Unit");
				jcmdUnitAdd.addActionListener(this);
			}
			
			//Checkboxen + JPanel
			{
				jpArmyAttribues = new JPanel();
				{
					jchbFlying = new JCheckBox();
					jpArmyAttribues.add(jchbFlying);
					jchbFlying.setText("Flying");
					jchbFlying.setPreferredSize(new java.awt.Dimension(174, 19));
					jchbFlying.addActionListener(this);
				}
				{
					jchbMechanized = new JCheckBox();
					jpArmyAttribues.add(jchbMechanized);
					jchbMechanized.setText("Mechanized");
					jchbMechanized.setPreferredSize(new java.awt.Dimension(174, 19));
					jchbMechanized.setSize(174, 19);
					jchbMechanized.addActionListener(this);
				}
				{
					jchbTired = new JCheckBox();
					jpArmyAttribues.add(jchbTired);
					jchbTired.setText("Tired");
					jchbTired.setPreferredSize(new java.awt.Dimension(174, 19));
					jchbTired.addActionListener(this);
				}
				{
					jchbFortified = new JCheckBox();
					jpArmyAttribues.add(jchbFortified);
					jchbFortified.setText("Fortified");
					jchbFortified.setPreferredSize(new java.awt.Dimension(174, 19));
					jchbFortified.addActionListener(this);
				}
				{
					jchbVigliant = new JCheckBox();
					jpArmyAttribues.add(jchbVigliant);
					jchbVigliant.setText("Vigliant");
					jchbVigliant.setPreferredSize(new java.awt.Dimension(174, 19));
					jchbVigliant.addActionListener(this);
				}
				{
					jchbAntiScouting = new JCheckBox();
					jpArmyAttribues.add(jchbAntiScouting);
					jchbAntiScouting.setText("Anti scouting");
					jchbAntiScouting.setPreferredSize(new java.awt.Dimension(174, 19));
					jchbAntiScouting.addActionListener(this);
				}
				{
					jchbUnderArtilleryFire = new JCheckBox();
					jpArmyAttribues.add(jchbUnderArtilleryFire);
					jchbUnderArtilleryFire.setText("Under artillery fire");
					jchbUnderArtilleryFire.setPreferredSize(new java.awt.Dimension(174, 19));
					jchbUnderArtilleryFire.addActionListener(this);
				}
				{
					jchbWithoutHQ = new JCheckBox();
					jpArmyAttribues.add(jchbWithoutHQ);
					jchbWithoutHQ.setText("Without HQ");
					jchbWithoutHQ.setPreferredSize(new java.awt.Dimension(174, 17));
					jchbWithoutHQ.addActionListener(this);
				}
			}

			//ScrollPanel + Listbox ArmyView
			{
				jspArmyView = new JScrollPane();
				{
					MyTableModel MainGUITableModel = 
							new MyTableModel();
					alMainGUITableModel.add(MainGUITableModel);
					jtblArmyView = new JTable();
					jspArmyView.setViewportView(jtblArmyView);
					jtblArmyView.setModel(MainGUITableModel);
					jtblArmyView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
					jtblArmyView.getColumn("Slot").setPreferredWidth(60);
					jtblArmyView.getColumn("Unitname").setPreferredWidth(407);
					jtblArmyView.getColumn("Points").setPreferredWidth(80);
					jtblArmyView.getColumn("Flying").setPreferredWidth(50);
					jtblArmyView.getColumn("Mechanized").setPreferredWidth(80);	
				}
			}
			
			//Combobox
			{
				ComboBoxModel jcbPlayerModel = 
						new DefaultComboBoxModel(
								new String[] {});
				jcbPlayer = new JComboBox();
				jcbPlayer.setModel(jcbPlayerModel);
				jcbPlayer.addActionListener(this);
			}
			{
				ComboBoxModel jcbPlayerArmyListModel = 
						new DefaultComboBoxModel(
								new String[] { });
				jcbPlayerArmyList = new JComboBox();
				jcbPlayerArmyList.setModel(jcbPlayerArmyListModel);
				jcbPlayerArmyList.addActionListener(this);
			}

			{
				ComboBoxModel jcbPlayerArmyList2Model = 
						new DefaultComboBoxModel(
								new String[] { "" });
				jcbPlayerArmyList2 = new JComboBox();
				jcbPlayerArmyList2.setModel(jcbPlayerArmyList2Model);
			}
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
				.addContainerGap()
				.add(thisLayout.createParallelGroup(GroupLayout.BASELINE)
				    .add(GroupLayout.BASELINE, jcmdPlayerAdd, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .add(GroupLayout.BASELINE, jtxtPlayerAdd, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(LayoutStyle.RELATED)
				.add(thisLayout.createParallelGroup(GroupLayout.BASELINE)
				    .add(GroupLayout.BASELINE, jcbPlayer, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .add(GroupLayout.BASELINE, jcmdPlayerRemove, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(LayoutStyle.RELATED)
				.add(thisLayout.createParallelGroup(GroupLayout.BASELINE)
				    .add(GroupLayout.BASELINE, jcmdArmyAdd, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .add(GroupLayout.BASELINE, jtxtArmyAdd, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(LayoutStyle.RELATED)
				.add(thisLayout.createParallelGroup(GroupLayout.BASELINE)
				    .add(GroupLayout.BASELINE, jcbPlayerArmyList2, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
				    .add(GroupLayout.BASELINE, jcmdUnitAdd, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
				    .add(GroupLayout.BASELINE, jcmdArmyMerge, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .add(GroupLayout.BASELINE, jcbPlayerArmyList, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .add(GroupLayout.BASELINE, jcmdArmyRemove, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(LayoutStyle.RELATED)
				.add(thisLayout.createParallelGroup()
				    .add(thisLayout.createSequentialGroup()
				        .add(jpArmyAttribues, GroupLayout.PREFERRED_SIZE, 195, GroupLayout.PREFERRED_SIZE))
				    .add(thisLayout.createSequentialGroup()
				        .add(jspArmyView, GroupLayout.PREFERRED_SIZE, 194, GroupLayout.PREFERRED_SIZE)))
				.addContainerGap(127, Short.MAX_VALUE));
			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
				.addContainerGap()
				.add(thisLayout.createParallelGroup()
				    .add(GroupLayout.LEADING, jpArmyAttribues, GroupLayout.PREFERRED_SIZE, 190, GroupLayout.PREFERRED_SIZE)
				    .add(GroupLayout.LEADING, thisLayout.createSequentialGroup()
				        .add(jcbPlayerArmyList, GroupLayout.PREFERRED_SIZE, 180, GroupLayout.PREFERRED_SIZE)
				        .add(10))
				    .add(GroupLayout.LEADING, thisLayout.createSequentialGroup()
				        .add(jtxtArmyAdd, GroupLayout.PREFERRED_SIZE, 180, GroupLayout.PREFERRED_SIZE)
				        .add(10))
				    .add(GroupLayout.LEADING, thisLayout.createSequentialGroup()
				        .add(jcbPlayer, GroupLayout.PREFERRED_SIZE, 180, GroupLayout.PREFERRED_SIZE)
				        .add(10))
				    .add(GroupLayout.LEADING, thisLayout.createSequentialGroup()
				        .add(jtxtPlayerAdd, GroupLayout.PREFERRED_SIZE, 180, GroupLayout.PREFERRED_SIZE)
				        .add(10)))
				.add(thisLayout.createParallelGroup()
				    .add(GroupLayout.LEADING, thisLayout.createSequentialGroup()
				        .add(jspArmyView, GroupLayout.PREFERRED_SIZE, 555, GroupLayout.PREFERRED_SIZE)
				        .addPreferredGap(LayoutStyle.RELATED, 0, Short.MAX_VALUE))
				    .add(GroupLayout.LEADING, thisLayout.createSequentialGroup()
				        .add(thisLayout.createParallelGroup()
				            .add(GroupLayout.LEADING, jcmdArmyRemove, 0, 131, Short.MAX_VALUE)
				            .add(thisLayout.createSequentialGroup()
				                .add(jcmdArmyAdd, GroupLayout.PREFERRED_SIZE, 131, GroupLayout.PREFERRED_SIZE)
				                .add(0, 0, Short.MAX_VALUE))
				            .add(thisLayout.createSequentialGroup()
				                .add(jcmdPlayerRemove, GroupLayout.PREFERRED_SIZE, 131, GroupLayout.PREFERRED_SIZE)
				                .add(0, 0, Short.MAX_VALUE))
				            .add(thisLayout.createSequentialGroup()
				                .add(jcmdPlayerAdd, GroupLayout.PREFERRED_SIZE, 131, GroupLayout.PREFERRED_SIZE)
				                .add(0, 0, Short.MAX_VALUE)))
				        .addPreferredGap(LayoutStyle.RELATED)
				        .add(jcmdUnitAdd, 0, 94, Short.MAX_VALUE)
				        .addPreferredGap(LayoutStyle.RELATED)
				        .add(jcmdArmyMerge, GroupLayout.PREFERRED_SIZE, 133, GroupLayout.PREFERRED_SIZE)
				        .addPreferredGap(LayoutStyle.RELATED)
				        .add(jcbPlayerArmyList2, GroupLayout.PREFERRED_SIZE, 186, GroupLayout.PREFERRED_SIZE)))
				.addContainerGap(89, 89));

			//Layoutsetzen
			pack();
			this.setSize(850, 469);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
		
	}
	
	
	public void actionPerformed(ActionEvent e){
		if (e.getSource() == jcmdPlayerAdd) {
			addPlayer();
		}if (e.getSource() == jcmdPlayerRemove) {
			removePlayer();
		}if (e.getSource() == jcmdArmyAdd) {
			addArmy();
		}if(e.getSource() == jcmdArmyRemove){
			removeArmy();
		}if (e.getSource() == jcmdArmyMerge) {
			mergeArmy();
		} if (e.getSource() == jcmdUnitAdd){
			addUnit();
		} if (e.getSource() == jcbPlayer) {
			changeJcbPlayer();
		} if (e.getSource() == jcbPlayerArmyList) {
			changeJcbPlayerArmyList();
		}if (e.getSource() == jchbFlying) {
			changeFlying();
		}if (e.getSource() == jchbMechanized) {
			changeMechanized();
		}if (e.getSource() == jchbTired) {
			changeTired();
		}if (e.getSource() == jchbFortified) {
			changeFortified();
		}if (e.getSource() == jchbVigliant) {
			changeVigliant();
		}if (e.getSource() == jchbAntiScouting) {
			changeAntiScounting();
		}if (e.getSource() == jchbUnderArtilleryFire) {
			changeUnderArtilleryFire();
		}if (e.getSource() == jchbWithoutHQ) {
			changeWithoutHQ();
		}
	}



	void addPlayer() {
		Integer i;
		if (jtxtPlayerAdd.getText().length() >0 ) {
			String txtContextPlayerAdd = jtxtPlayerAdd.getText();
			jcbPlayer.removeAllItems();
			Player objPlayer = new Player(txtContextPlayerAdd);
			alPlayer.add(objPlayer);
			Object ia[] = alPlayer.toArray();
			for (i=0;i<ia.length; i++){
				jcbPlayer.addItem(ia[i]);	
			}
			jtxtPlayerAdd.setText("");
		}else {
			JOptionPane.showMessageDialog(null, "Es konnte kein Spieler angelegt werden da Sie keinen Spielernamen angegeben haben.", "Kein Spielername eingegeben!", JOptionPane.ERROR_MESSAGE);
			
		}
	}
	
	void removePlayer(){
		if (jcbPlayer.getItemCount() > 0){
			if (jcbPlayer.getItemCount() == 1){
				Integer x;
				x = jcbPlayer.getSelectedIndex();
				jcbPlayer.removeAllItems();
				jcbPlayerArmyList.removeAllItems();
				jcbPlayerArmyList2.removeAllItems();
				if (alPlayer.get(x).alArmy.size() > 0){
					alPlayer.get(x).deleteAllArmys();
				}
				alPlayer.removeAll(alPlayer);
			}else{
				Integer x;
				Integer y;
				Integer i;
				Integer j;
				x = jcbPlayer.getSelectedIndex();
				if (alPlayer.get(x).alArmy.size() > 0){
					alPlayer.get(x).deleteAllArmys();
				}
				alPlayer.remove(alPlayer.get(x));
				jcbPlayer.removeAllItems();
				Object ai1[] = alPlayer.toArray();
				for (j = 0; j < ai1.length; j++){
					jcbPlayer.addItem(ai1[j]);
				}
				y = jcbPlayer.getSelectedIndex();
				if (alPlayer.get(y).alArmy.size() > 0){
					jcbPlayerArmyList.removeAllItems();
					jcbPlayerArmyList2.removeAllItems();
					Object ai2[] = alPlayer.get(y).alArmy.toArray();
					for (i=0; i <ai2.length; i++){
						jcbPlayerArmyList.addItem(ai2[i]);
						jcbPlayerArmyList2.addItem(ai2[i]);
					}
				}
			}
		}
		else{
			JOptionPane.showMessageDialog(null, "Es ist kein Spieler vorhanden den man löschen könnte.", "Kein Spieler vorhanden!", JOptionPane.ERROR_MESSAGE);
		}

	}
		
	void addArmy(){
		if (jcbPlayer.getItemCount() > 0){
			if (jtxtArmyAdd.getText().length() >0 ){
				Integer x;
				Integer i;
				x = jcbPlayer.getSelectedIndex();
				jcbPlayerArmyList.removeAllItems();
				jcbPlayerArmyList2.removeAllItems();
				alPlayer.get(x).addArmy(jtxtArmyAdd.getText());
				Object ai[] = alPlayer.get(x).alArmy.toArray();
	            for (i = 0; i < ai.length; i++){
	                jcbPlayerArmyList.addItem(ai[i]);
					jcbPlayerArmyList2.addItem(ai[i]);
	            }
	            jtxtArmyAdd.setText("");
			}
			else {
				JOptionPane.showMessageDialog(null, "Es konnte keine Armee angelegt werden da Sie keinen Armeenamen angegeben haben.", "Kein Armeename eingegeben!", JOptionPane.ERROR_MESSAGE);
			}
		}
		else{
			JOptionPane.showMessageDialog(null, "Kein Spieler ausgewählt.", "Kein Spieler ausgewählt!", JOptionPane.ERROR_MESSAGE);
		}

		
	}
	
	void removeArmy(){
		if(jcbPlayer.getItemCount() > 0){
			if (jcbPlayerArmyList.getItemCount() > 0){
				Integer i;
				Integer x;
				Integer y;
				x = jcbPlayer.getSelectedIndex();
				y = jcbPlayerArmyList.getSelectedIndex();
				alPlayer.get(x).deleteOneArmy(alPlayer.get(x).alArmy.get(y));
				jcbPlayerArmyList.removeAllItems();
				jcbPlayerArmyList2.removeAllItems();
				Object ai[] = alPlayer.get(x).alArmy.toArray();
				if (ai.length > 0){
					for (i=0; i <ai.length; i++){
						jcbPlayerArmyList.addItem(ai[i]);
						jcbPlayerArmyList2.addItem(ai[i]);
					}
				}
			}else{
				JOptionPane.showMessageDialog(null, "Keine Armee ausgewählt.", "Keine Armee ausgewählt!", JOptionPane.ERROR_MESSAGE);
			}
		}else{
			JOptionPane.showMessageDialog(null, "Kein Spieler ausgewählt.", "Kein Spieler ausgewählt!", JOptionPane.ERROR_MESSAGE);
		}

	}
 
Class: MainGUI ------Teil2
Java:
	void mergeArmy(){
		if (jcbPlayer.getItemCount() > 0){
			if (jcbPlayerArmyList.getItemCount() > 0) {
				if (jcbPlayerArmyList2.getItemCount() > 0){
					if (jcbPlayerArmyList.getSelectedIndex() != jcbPlayerArmyList2.getSelectedIndex()){
						Integer x;
						Integer y;
						Integer z;
						Integer i;
						Integer j;
						Integer k;
						Boolean bolFlyingOK1 = false;
						Boolean bolFlyingOK2 = false;
						Boolean bolMechanizedOK1 = true;
						Boolean bolMechanizedOK2 = true;
						x = jcbPlayer.getSelectedIndex();
						y = jcbPlayerArmyList.getSelectedIndex();
						z = jcbPlayerArmyList2.getSelectedIndex();
						Object ai[] = alPlayer.get(x).alArmy.get(z).alUnit.toArray();
						for (i = 0; i < ai.length; i++){
							alPlayer.get(x).alArmy.get(y).alUnit.add((Unit) ai[i]);
						}
			            if (alPlayer.get(x).alArmy.get(y).getBolFlying() == false){
			            	alPlayer.get(x).alArmy.get(y).setBolFlying(false);
			            }if(alPlayer.get(x).alArmy.get(y).getBolFlying() == true){
			            	if(alPlayer.get(x).alArmy.get(z).getBolFlying() == false){
			            		alPlayer.get(x).alArmy.get(y).setBolFlying(false);
			            	}if(alPlayer.get(x).alArmy.get(z).getBolFlying() == true){
			            		alPlayer.get(x).alArmy.get(y).setBolFlying(true);
			            	}
			            }
			            if (alPlayer.get(x).alArmy.get(y).getBolMechanized() == false){
		            		alPlayer.get(x).alArmy.get(y).setBolMechanized(false);
			            }if(alPlayer.get(x).alArmy.get(y).getBolMechanized() == true){
			            	if(alPlayer.get(x).alArmy.get(z).getBolMechanized() == false){
			            		alPlayer.get(x).alArmy.get(y).setBolMechanized(false);
			            	}if(alPlayer.get(x).alArmy.get(z).getBolMechanized() == true){
			            		alPlayer.get(x).alArmy.get(y).setBolMechanized(true);
		            		}
			            }
			            if (alPlayer.get(x).alArmy.get(z).getBolTired() == true){
			            	alPlayer.get(x).alArmy.get(y).setBolTired(true);
			            }
			            if (alPlayer.get(x).alArmy.get(z).getBolFortified() == true){
			            	alPlayer.get(x).alArmy.get(y).setBolFortified(true);
			            }
			            if (alPlayer.get(x).alArmy.get(z).getBolVigliant() == true){
			            	alPlayer.get(x).alArmy.get(y).setBolVigliant(true);
			            }
			            if (alPlayer.get(x).alArmy.get(z).getBolAntiScouting() == true){
			            	alPlayer.get(x).alArmy.get(y).setBolAntiScouting(true);
			            }
			            if (alPlayer.get(x).alArmy.get(z).getBolUnderArtilleryFire() == true){
			            	alPlayer.get(x).alArmy.get(y).setBolUnderArtilleryFire(true);
			            }
			            if (alPlayer.get(x).alArmy.get(y).getBolWithoutHQ() == false){
			            	if (alPlayer.get(x).alArmy.get(z).getBolWithoutHQ() == false){
			            		alPlayer.get(x).alArmy.get(y).setBolWithoutHQ(false);
			            	}if(alPlayer.get(x).alArmy.get(z).getBolWithoutHQ() == true)
			            		alPlayer.get(x).alArmy.get(y).setBolWithoutHQ(false);
			            }if (alPlayer.get(x).alArmy.get(y).getBolWithoutHQ() == true){
			            	if(alPlayer.get(x).alArmy.get(z).getBolWithoutHQ() == false){
			            		alPlayer.get(x).alArmy.get(y).setBolWithoutHQ(false);
			            	}if(alPlayer.get(x).alArmy.get(z).getBolWithoutHQ() == true){
			            		alPlayer.get(x).alArmy.get(y).setBolWithoutHQ(true);
			            	}
			            }

						alPlayer.get(x).deleteOneArmy(alPlayer.get(x).alArmy.get(z));
						jcbPlayerArmyList.removeAllItems();
						jcbPlayerArmyList2.removeAllItems();
						Object ai2[] = alPlayer.get(x).alArmy.toArray();
			            for (i = 0; i < ai2.length; i++){
			                jcbPlayerArmyList.addItem(ai2[i]);
							jcbPlayerArmyList2.addItem(ai2[i]);
			            }
					}else {
						JOptionPane.showMessageDialog(null, "Die Armee kann nicht mit sich selber zusammengelegt werden.", "Falsche Auswahl zum zusammenlegen!", JOptionPane.ERROR_MESSAGE);
					}
				}else{
					JOptionPane.showMessageDialog(null, "Es wurde keine zweite Armee ausgewählt.", "Keine zweite Armee angegeben!", JOptionPane.ERROR_MESSAGE);
				}
			}else{
				JOptionPane.showMessageDialog(null, "Es wurde keine Armee angegeben.", "Keine Armee als Ziel angegeben!", JOptionPane.ERROR_MESSAGE);
			}
		}else{
			JOptionPane.showMessageDialog(null, "Kein Spieler ausgewählt.", "Kein Spieler ausgewählt!", JOptionPane.ERROR_MESSAGE);
		}
	}
	
	void addUnit(){
		if (jcbPlayer.getItemCount() > 0){
			if(jcbPlayerArmyList.getItemCount() > 0){
				intSelectedPlayer = jcbPlayer.getSelectedIndex();
				intSelectedArmy = jcbPlayerArmyList.getSelectedIndex();
				UnitAddGUI GUIUnitAddGUI = new UnitAddGUI(alPlayer.get(intSelectedPlayer).alArmy.get(intSelectedArmy) );
				GUIUnitAddGUI.setVisible(true);
			}
			else{
				JOptionPane.showMessageDialog(null, "Keine Armee ausgewählt.", "Keine Spieler ausgewählt!", JOptionPane.ERROR_MESSAGE);
			}
		}
		else{
			JOptionPane.showMessageDialog(null, "Kein Spieler ausgewählt.", "Kein Spieler ausgewählt!", JOptionPane.ERROR_MESSAGE);
		}

	}
	
	void changeJcbPlayer(){
		if (jcbPlayer.getItemCount() > 0){
			Integer i;
			Integer z;
			Integer y;
			z = jcbPlayer.getSelectedIndex();
			Object ai[] = alPlayer.get(z).alArmy.toArray();
			jcbPlayerArmyList.removeAllItems();
			jcbPlayerArmyList2.removeAllItems();
			if (ai.length >= 1){
				for (i = 0; i < ai.length; i++) {
					jcbPlayerArmyList.addItem(ai[i]);
					jcbPlayerArmyList2.addItem(ai[i]);
				}
			y = jcbPlayerArmyList.getSelectedIndex();
			jchbFlying.setSelected(alPlayer.get(z).alArmy.get(y).getBolFlying());
			jchbMechanized.setSelected(alPlayer.get(z).alArmy.get(y).getBolMechanized());
			jchbTired.setSelected(alPlayer.get(z).alArmy.get(y).getBolTired());
			jchbFortified.setSelected(alPlayer.get(z).alArmy.get(y).getBolFortified());
			jchbVigliant.setSelected(alPlayer.get(z).alArmy.get(y).getBolVigliant());
			jchbAntiScouting.setSelected(alPlayer.get(z).alArmy.get(y).getBolAntiScouting());
			jchbUnderArtilleryFire.setSelected(alPlayer.get(z).alArmy.get(y).getBolUnderArtilleryFire());
			jchbWithoutHQ.setSelected(alPlayer.get(z).alArmy.get(y).getBolWithoutHQ());
			}
		}
	}
	
	void changeJcbPlayerArmyList(){
		if (jcbPlayer.getItemCount() > 0) {
			if (jcbPlayerArmyList.getItemCount() > 0){
				Integer z;
				Integer y;
				Integer i;
				z = jcbPlayer.getSelectedIndex();
				y = jcbPlayerArmyList.getSelectedIndex();
				Object ai[] = alPlayer.get(z).alArmy.get(y).alUnit.toArray();
				alListModel.get(0).removeAllElements();
				for (i = 0; i < ai.length; i++){
					alListModel.get(0).addElement(alPlayer.get(z).alArmy.get(y).alUnit.get(i).toStringAll());
				}
				jchbFlying.setSelected(alPlayer.get(z).alArmy.get(y).getBolFlying());
				jchbMechanized.setSelected(alPlayer.get(z).alArmy.get(y).getBolMechanized());
				jchbTired.setSelected(alPlayer.get(z).alArmy.get(y).getBolTired());
				jchbFortified.setSelected(alPlayer.get(z).alArmy.get(y).getBolFortified());
				jchbVigliant.setSelected(alPlayer.get(z).alArmy.get(y).getBolVigliant());
				jchbAntiScouting.setSelected(alPlayer.get(z).alArmy.get(y).getBolAntiScouting());
				jchbUnderArtilleryFire.setSelected(alPlayer.get(z).alArmy.get(y).getBolUnderArtilleryFire());
				jchbWithoutHQ.setSelected(alPlayer.get(z).alArmy.get(y).getBolWithoutHQ());
			}
		}
	}
	
	private void changeFlying() {
		if (jcbPlayer.getItemCount() > 0){
			if (jcbPlayerArmyList.getItemCount() > 0){
				Integer z;
				Integer y;
				z = jcbPlayer.getSelectedIndex();
				y = jcbPlayerArmyList.getSelectedIndex();
				alPlayer.get(z).alArmy.get(y).setBolFlying(jchbFlying.isSelected());
			}
		}	
	}
	
	private void changeMechanized() {
		if (jcbPlayer.getItemCount() > 0){
			if (jcbPlayerArmyList.getItemCount() > 0){
				Integer z;
				Integer y;
				z = jcbPlayer.getSelectedIndex();
				y = jcbPlayerArmyList.getSelectedIndex();
				alPlayer.get(z).alArmy.get(y).setBolMechanized(jchbMechanized.isSelected());
			}
		}	
	}
	
	private void changeTired() {
		if (jcbPlayer.getItemCount() > 0){
			if (jcbPlayerArmyList.getItemCount() > 0){
				Integer z;
				Integer y;
				z = jcbPlayer.getSelectedIndex();
				y = jcbPlayerArmyList.getSelectedIndex();
				alPlayer.get(z).alArmy.get(y).setBolTired(jchbTired.isSelected());
			}
		}
	}
	
	private void changeFortified() {
		if (jcbPlayer.getItemCount() > 0){
			if (jcbPlayerArmyList.getItemCount() > 0){
				Integer z;
				Integer y;
				z = jcbPlayer.getSelectedIndex();
				y = jcbPlayerArmyList.getSelectedIndex();
				alPlayer.get(z).alArmy.get(y).setBolFortified(jchbFortified.isSelected());
			}
		}	
	}
	
	private void changeVigliant() {
		if (jcbPlayer.getItemCount() > 0){
			if (jcbPlayerArmyList.getItemCount() > 0){
				Integer z;
				Integer y;
				z = jcbPlayer.getSelectedIndex();
				y = jcbPlayerArmyList.getSelectedIndex();
				alPlayer.get(z).alArmy.get(y).setBolVigliant(jchbVigliant.isSelected());
			}
		}	
	}
	
	private void changeAntiScounting() {
		if (jcbPlayer.getItemCount() > 0){
			if (jcbPlayerArmyList.getItemCount() > 0){
				Integer z;
				Integer y;
				z = jcbPlayer.getSelectedIndex();
				y = jcbPlayerArmyList.getSelectedIndex();
				alPlayer.get(z).alArmy.get(y).setBolAntiScouting(jchbAntiScouting.isSelected());
			}
		}
	}
	
	private void changeUnderArtilleryFire() {
		if (jcbPlayer.getItemCount() > 0){
			if (jcbPlayerArmyList.getItemCount() > 0){
				Integer z;
				Integer y;
				z = jcbPlayer.getSelectedIndex();
				y = jcbPlayerArmyList.getSelectedIndex();
				alPlayer.get(z).alArmy.get(y).setBolUnderArtilleryFire(jchbUnderArtilleryFire.isSelected());
			}
		}
	}
	
	private void changeWithoutHQ() {
		if (jcbPlayer.getItemCount() > 0){
			if (jcbPlayerArmyList.getItemCount() > 0){
				Integer z;
				Integer y;
				z = jcbPlayer.getSelectedIndex();
				y = jcbPlayerArmyList.getSelectedIndex();
				alPlayer.get(z).alArmy.get(y).setBolWithoutHQ(jchbWithoutHQ.isSelected());
			}
		}
	}
}

Class: UnitAddGUI
Java:
package GUI;
import java.awt.AlphaComposite;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;

import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;

import Daten.Army;
import Daten.Unit;
import GUI.MainGUI;
import Daten.MyTableModel;

public class UnitAddGUI extends javax.swing.JFrame  implements ActionListener{

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JScrollPane jspUnitList;
	private JTextField jtxtEinheitName;
	private JButton jcmdUnitRemove;
	private JButton jcmdUnitEquiptmentAdd;
	private JButton jcmdUnitAdd;
	private JTextField jtxtPoints;
	private JLabel jlblPoints;
	private JCheckBox jcbMechanized;
	private JCheckBox jcbFlying;
	private JTable jtblUnitList;
	private JLabel jlblUnitName;
	private JComboBox jcbUnitSlot;
	public Integer intSelectedArmyFromGUI;
	public Integer intSelectedPlayerFromGUI;
	public ArrayList<Army> alArmyUnitAdd = new ArrayList<Army>();
	public ArrayList<MyTableModel> alUnitAddTableModel = new ArrayList<MyTableModel>();

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				UnitAddGUI inst = new UnitAddGUI();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public UnitAddGUI() {
		super();
		initGUI();
	}
	
	public UnitAddGUI(Army alArmy) {
		super();
		alArmyUnitAdd.add(alArmy);
		System.out.println(alArmyUnitAdd.toArray().length);
		System.out.println(alArmy);
		initGUI();

	}
	
	private void initGUI() {
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)getContentPane());
			getContentPane().setLayout(thisLayout);
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{
				jspUnitList = new JScrollPane();
				{
					MyTableModel UnitAddTableModel = 
							new MyTableModel(alArmyUnitAdd.get(0).alUnit);
					alUnitAddTableModel.add(UnitAddTableModel);
					jtblUnitList = new JTable();
					jspUnitList.setViewportView(jtblUnitList);
					jtblUnitList.setModel(UnitAddTableModel);
					jtblUnitList.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
					jtblUnitList.getColumn("Slot").setPreferredWidth(60);
					jtblUnitList.getColumn("Unitname").setPreferredWidth(407);
					jtblUnitList.getColumn("Points").setPreferredWidth(80);
					jtblUnitList.getColumn("Flying").setPreferredWidth(50);
					jtblUnitList.getColumn("Mechanized").setPreferredWidth(80);					
				}
			}
			{
				jcbFlying = new JCheckBox();
				jcbFlying.setText("Flying");
			}
			{
				jcbMechanized = new JCheckBox();
				jcbMechanized.setText("Mechanized");
			}
			{
				ComboBoxModel jcbUnitSlotModel = 
						new DefaultComboBoxModel(
								new String[] { "HQ", "Standard", "Elite", "Support","Sturm" });
				jcbUnitSlot = new JComboBox();
				jcbUnitSlot.setModel(jcbUnitSlotModel);
			}
			{
				jlblUnitName = new JLabel();
				jlblUnitName.setText("Unitname:");
			}
			{
				jtxtEinheitName = new JTextField();
			}
			{
				jcmdUnitAdd = new JButton();
				jcmdUnitAdd.setText("Add Unit");
				jcmdUnitAdd.addActionListener(this);
			}
			{
				jcmdUnitEquiptmentAdd = new JButton();
				jcmdUnitEquiptmentAdd.setText("Add Equiptment");
				jcmdUnitEquiptmentAdd.addActionListener(this);
			}
			{
				jcmdUnitRemove = new JButton();
				jcmdUnitRemove.setText("Remove Unit");
				jcmdUnitRemove.addActionListener(this);
			}
			{
				jlblPoints = new JLabel();
				jlblPoints.setText("Points:");
			}
			{
				jtxtPoints = new JTextField();
			}
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
				.addGap(7)
				.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(jcbUnitSlot, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(jlblUnitName, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(jtxtEinheitName, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(jlblPoints, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(jtxtPoints, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
				.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(jcmdUnitAdd, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(jcbFlying, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(jcbMechanized, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
				.addComponent(jspUnitList, GroupLayout.PREFERRED_SIZE, 325, GroupLayout.PREFERRED_SIZE)
				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
				.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(jcmdUnitEquiptmentAdd, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(jcmdUnitRemove, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
				.addGap(6));
			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
				.addContainerGap()
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addGroup(thisLayout.createParallelGroup()
				            .addGroup(thisLayout.createSequentialGroup()
				                .addGroup(thisLayout.createParallelGroup()
				                    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				                        .addComponent(jcbUnitSlot, GroupLayout.PREFERRED_SIZE, 132, GroupLayout.PREFERRED_SIZE)
				                        .addGap(25)
				                        .addComponent(jlblUnitName, GroupLayout.PREFERRED_SIZE, 63, GroupLayout.PREFERRED_SIZE)
				                        .addGap(0, 0, Short.MAX_VALUE))
				                    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				                        .addGap(0, 0, Short.MAX_VALUE)
				                        .addComponent(jcbFlying, GroupLayout.PREFERRED_SIZE, 93, GroupLayout.PREFERRED_SIZE)
				                        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
				                        .addComponent(jcbMechanized, GroupLayout.PREFERRED_SIZE, 105, GroupLayout.PREFERRED_SIZE)
				                        .addGap(18)))
				                .addGap(12)
				                .addGroup(thisLayout.createParallelGroup()
				                    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				                        .addComponent(jcmdUnitAdd, GroupLayout.PREFERRED_SIZE, 98, GroupLayout.PREFERRED_SIZE)
				                        .addGap(189))
				                    .addComponent(jtxtEinheitName, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 287, GroupLayout.PREFERRED_SIZE)))
				            .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				                .addComponent(jcmdUnitEquiptmentAdd, GroupLayout.PREFERRED_SIZE, 168, GroupLayout.PREFERRED_SIZE)
				                .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
				                .addComponent(jcmdUnitRemove, GroupLayout.PREFERRED_SIZE, 131, GroupLayout.PREFERRED_SIZE)
				                .addGap(209)))
				        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
				        .addComponent(jlblPoints, GroupLayout.PREFERRED_SIZE, 47, GroupLayout.PREFERRED_SIZE)
				        .addComponent(jtxtPoints, GroupLayout.PREFERRED_SIZE, 95, GroupLayout.PREFERRED_SIZE))
				    .addComponent(jspUnitList, GroupLayout.Alignment.LEADING, 0, 677, Short.MAX_VALUE))
				.addContainerGap());
			pack();
			this.setSize(701, 457);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	public void actionPerformed(ActionEvent e){
		if (e.getSource() == jcmdUnitAdd) {
			addUnit();
		}if (e.getSource() == jcmdUnitEquiptmentAdd) {
			addUnitEquiptment();
		}if (e.getSource() == jcmdUnitRemove) {
			removeUnit();
		}
	}
	
	void addUnit(){
		String strNewUnitName = jtxtEinheitName.getText();
		String strNewUnitSlot = jcbUnitSlot.getSelectedItem().toString();
		Integer intNewUnitCosts = Integer.parseInt(jtxtPoints.getText());
		Unit objUnit = new Unit(strNewUnitName, strNewUnitSlot, intNewUnitCosts, jcbFlying.isSelected(), jcbMechanized.isSelected());
		System.out.println(alArmyUnitAdd.toArray().length);
		alArmyUnitAdd.get(0).alUnit.add(objUnit);
		alUnitAddTableModel.get(0).fireTableDataChanged();
	}
	
	void addUnitEquiptment(){
		//Unit objUnit = new Unit(jtxtEinheitName.getText(), Integer.parseInt(jtxtPoints.getText()), jcbUnitSlot.getSelectedItem());
		//alArmyUnitAdd.get(0).alUnit.add(objUnit);
		//System.out.println(objUnit);
	}
	
	void removeUnit(){
		alArmyUnitAdd.get(0).alUnit.remove(jtblUnitList.getSelectedRow());
		alUnitAddTableModel.get(0).fireTableDataChanged();
	}
	

}

Class: UnitEquipmentAddGUI
Java:
package GUI;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;



public class UnitEquipmentAddGUI extends javax.swing.JFrame {
	private JTextField jtxtUnitName;
	private JButton jcmdEquipmentRemove;
	private JButton jcmdEquipmentAdd;
	private JLabel jlblUnitName;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				UnitEquipmentAddGUI inst = new UnitEquipmentAddGUI();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public UnitEquipmentAddGUI() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)getContentPane());
			getContentPane().setLayout(thisLayout);
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{
				jtxtUnitName = new JTextField();
			}
			{
				jlblUnitName = new JLabel();
				jlblUnitName.setText("Equipmentname:");
			}
			{
				jcmdEquipmentAdd = new JButton();
				jcmdEquipmentAdd.setText("Add Equipment");
			}
			{
				jcmdEquipmentRemove = new JButton();
				jcmdEquipmentRemove.setText("Remove Equipment");
			}
			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
				.addContainerGap()
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(jlblUnitName, GroupLayout.PREFERRED_SIZE, 108, GroupLayout.PREFERRED_SIZE)
				        .addComponent(jtxtUnitName, GroupLayout.PREFERRED_SIZE, 249, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE))
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(jcmdEquipmentAdd, GroupLayout.PREFERRED_SIZE, 124, GroupLayout.PREFERRED_SIZE)
				        .addGap(11)
				        .addComponent(jcmdEquipmentRemove, GroupLayout.PREFERRED_SIZE, 133, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 89, GroupLayout.PREFERRED_SIZE)))
				.addContainerGap(158, 158));
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
				.addContainerGap()
				.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(jtxtUnitName, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(jlblUnitName, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
				.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(jcmdEquipmentAdd, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(jcmdEquipmentRemove, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
				.addContainerGap(251, Short.MAX_VALUE));
			pack();
			this.setSize(527, 363);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
 
Dann solltest du den Konstruktor deines TableModels:
Java:
public MyTableModel() {
 
    }
in den hier ändern:
Java:
public MyTableModel() {
 this.data=new ArrayList<Unit>();
    }
 
Vielen Dank für die Rasche antwort, da hab ich wohl den Wald vor lauter bäumen nicht gesehen....

Nun gibt es aber das nächste Problem... es aktualisiert mir die Tabelle nicht, obwohl ich per klick auf einen Button folgenden code aufrufe:

Java:
alMainGUITableModel.get(0).fireTableDataChanged();

Bei der jTabel in dem UnitAddGUI wird mit dem Konstruktor direkt die alUnit-Arraylist referenziert. Dies wird nun allerdings bei dem MainGUI nicht da ich eine Leere Arraylist in die List "data" übergebe.

Hat jemand eine Idee wie ich die referenz nachträglich nach dem GUI aufbau machen könnte ohne dass es mir das jedesmal bei einem "button-klick"-event eine neue referenz erstellt?

Hm... If-Abfrage mit einem Boolean wert und beim ersten mal den wert von False auf True setzen? Gibt es einen "schöneren" Weg?

Also sprich sowas:
Java:
Public Class MainGUI(){
public Boolean bolReferenz = false;
...JavaCode....

...Button-klickevent....
if(bolReferenz = false){
...Rufe eine setMethode auf die die alUnit-ArrayList referenziert
}
...JavaCode...

Problem ist halt dass es die ArrayList "alUnit" die ich eigentlich übergeben müsste am anfang nicht gibt beim GUI aufbau, die wird erst noch instanziert während man Spieler, Armeen und Einheiten hinzufügt..
 
Scheint mit der 2. Wald zu sein....
ich habe mir deine 1500 Zeile Code zwar nicht durchgelesen (ich sehe auch keine Notwendigkeit das zu tun, da es mit deinem problem nix zu tun hat), aber ich glaube, dur brauchts nur eine einfache setData(List<Unit> data) in deinem TableModel.
In der Methode unbedingt fireTableDataChanged aufrufen, um anzuzeigen, dass sich der Inhalt des models geändert hat!
 

Zurück
Oben