JScrollPane zerschießt JTable

Hallo,

ich denke das wird nur was mit Code.
Bitte Code- oder Java-Tags benutzen

Grüße
 
Zuletzt bearbeitet:
Das wäre die Tabelle.
Code:
	public class PlaylistiFrame extends JInternalFrame {
	
	JPopupMenu pum;
	JMenuItem play;
	
	JTable playlist;
	TableModel model;
	DefaultTableCellRenderer dcr;
	
	int nprow;
	
	int b;
	
	final String[] columnNames = {"Nr","Titel", "Zeit"};
	
	public PlaylistiFrame() {
		
		setSize(500, 700);
		setVisible(true);
		setLocation(500, 5);
		
		InitPopUpMenu();
		
		List();
		
	}

public void List() {
		
		if (playlist != null) remove(playlist);
		
		model = new DefaultTableModel(Main.pl.getPlaylist(), columnNames);
		
		playlist = new JTable(model){
			public boolean isCellEditable(int x, int y) {
				return false;
			}
			public Component prepareRenderer(TableCellRenderer renderer, int index_row, int index_col) {
				Component comp = super.prepareRenderer(renderer, index_row, index_col);
				if (index_row == nprow) { 
					comp.setForeground(Color.RED);
				}
				else {
					if (isCellSelected(index_row, index_col) == true) {
						comp.setForeground(Color.WHITE);
					}
					else comp.setForeground(Color.BLACK);
				}
		        return comp;
			}
		};

		JScrollPane scp = new JScrollPane(playlist);
		
		
		playlist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		
		playlist.addMouseListener(Main.ifplml);
		add(scp);
	
		
	}

Und das die Daten.
Code:
	public void updatePlaylist(Object[] info) {
		
		int z = 1;
		
		Object[][] fpl = new Object[i][4];
		if (this.fpl != null) {
			for (int x = this.fpl.length; x > 0; x--) {
				fpl[x-1][0] = this.fpl[x-1][0];
				fpl[x-1][1] = this.fpl[x-1][1];
				fpl[x-1][2] = this.fpl[x-1][2];
				fpl[x-1][3] = this.fpl[x-1][3];
			}
		}
		
		fpl[i-1][0] = info[0];
		fpl[i-1][1] = info[1];
		fpl[i-1][2] = info[2];
		fpl[i-1][3] = info[3];
		
		pl = new Object[i][3];
		
		for (int x = 0; x != fpl.length; x++) {
			pl[x][0] = z;
			pl[x][1] = fpl[x][0];
			pl[x][2] = fpl[x][1];
			z++;
		}
	}
pl[][] ist das Objekt welches übergeben wird.
 
Zuletzt bearbeitet:
Java:
public void updatePlaylist(Object[] info) {
		
		int z = 1;
		
		Object[][] fpl = new Object[i][4];
		if (this.fpl != null) {
			for (int x = this.fpl.length; x > 0; x--) {
				fpl[x-1][0] = this.fpl[x-1][0];
				fpl[x-1][1] = this.fpl[x-1][1];
				fpl[x-1][2] = this.fpl[x-1][2];
				fpl[x-1][3] = this.fpl[x-1][3];
			}
		}
		
		fpl[i-1][0] = info[0];
		fpl[i-1][1] = info[1];
		fpl[i-1][2] = info[2];
		fpl[i-1][3] = info[3];
		
		pl = new Object[i][3];
		
		for (int x = 0; x != fpl.length; x++) {
			pl[x][0] = z;
			pl[x][1] = fpl[x][0];
			pl[x][2] = fpl[x][1];
			z++;
		}
	}

Das wirkt auf mich sehr kompliziert und kompliziert heißt fehleranfällig! Hast du es schonmal mit dynamischen Arrays versucht? Ein Beispiel hierfür wäre ArrayList (http://java.sun.com/j2se/1.4.2/docs/api/java/util/ArrayList.html).
Dieser ArrayList fügst du dann einfach Object[] info hinzu.
 
Hi,
hab den Fehler schon gefunden. Das mit den Arrays hab ich mittlerweile auch vereinfacht, hatte ich im ersten Moment nicht erkannt gehabt!
Also Fehler war:
Code:
if (playlist != null) remove(playlist);
Die Zeile refresht sozusagen den JTable, nur wenn ich den JTable jetzt nicht mehr direkt einbette sondern über die JScrollPane muss des auch folglich so heißen:
Code:
if (playlist != null) remove(scp);

Trotzdem Danke an alle!

Grüße..
 

Neue Beiträge

Zurück