jTable Spaltenbreite lässt sich nicht ändern

Tacko

Aktives Mitglied
Hallo allerseits,

ich sitze gerade an einer jTable, welche unterschiedlich breite Spalten haben soll. Leider habe ich bis jetzt keine Möglichkeit gefunden dies zu realisieren.
Ich bin zwar hier im Forum auf diesen Beitrag gestoßen, der mir aber auch nicht weiter helfen kann. Hier mein Code:

Java:
inhalt = new String [0][5];
	    DTM_Model = new DefaultTableModel(inhalt, ueberschrift);
	    jT_Tabelle = new JTable (DTM_Model){
            public boolean isCellEditable(int x, int y) {
                return false;
            }
        };

        jT_Tabelle.setLayout(null);

        jT_Tabelle.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
       
        jT_Tabelle.getColumn("Datum").setMaxWidth(200);
        jT_Tabelle.getColumn("Datum").setMinWidth(200);
        jT_Tabelle.getColumn("Betreff").setMaxWidth(490);
        jT_Tabelle.getColumn("Betreff").setMinWidth(490);
        jT_Tabelle.getColumn("Kategorie").setMaxWidth(166);
        jT_Tabelle.getColumn("Kategorie").setMinWidth(166);
        jT_Tabelle.getColumn("Betrag in €").setMaxWidth(1000);
        jT_Tabelle.getColumn("Betrag in €").setMinWidth(1000);
        jT_Tabelle.getColumn("Saldo in €").setMaxWidth(80);
        jT_Tabelle.getColumn("Saldo in €").setMinWidth(80);

Ich hoffe ihr könnt mir weiterhelfen 🙂

LG. Tacko
 
nein leider geht auch das nicht... :/

hier wies momentan aussieht:
Java:
 inhalt = new String [0][5];
	    DTM_Model = new DefaultTableModel(inhalt, ueberschrift);
	    jT_Tabelle = new JTable (DTM_Model){
            public boolean isCellEditable(int x, int y) {
                return false;
            }
        };

        jT_Tabelle.setLayout(null);

        jT_Tabelle.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
       
        jT_Tabelle.getColumnModel().getColumn(0).setMaxWidth(200);
        jT_Tabelle.getColumnModel().getColumn(0).setMinWidth(200);
        jT_Tabelle.getColumnModel().getColumn(1).setMaxWidth(490);
        jT_Tabelle.getColumnModel().getColumn(1).setMinWidth(490);
        jT_Tabelle.getColumnModel().getColumn(2).setWidth(166);
        jT_Tabelle.getColumnModel().getColumn(2).setMinWidth(166);
        jT_Tabelle.getColumnModel().getColumn(3).setMaxWidth(1000);
        jT_Tabelle.getColumnModel().getColumn(3).setMinWidth(1000);
        jT_Tabelle.getColumnModel().getColumn(4).setWidth(80);
        jT_Tabelle.getColumnModel().getColumn(4).setMinWidth(80);
 
oh, dass warn tipp den ich iwo anderes gelesen hab um mein Problem zu lösen. Da stand, dass man das Layout auf null setzen soll, wenn man es nicht bereits anders belegt hat.
 
Was soll das darstellen?
Java:
jT_Tabelle.setLayout(null);

und das:

Java:
//...
jT_Tabelle.getColumnModel().getColumn(2).setWidth(166);
//...
jT_Tabelle.getColumnModel().getColumn(4).setWidth(80);
//...

? Wenn das dann immernoch nicht funktioniert, liegt der Fehler wohl woanders als in dem Code den uns gezeigt hast.
 

Zurück
Oben