I would like to be able to add 'n' columns programmatically and SET THEIR TITLE as I add them. I have 2 questions:
1. How can I change the title? (not by seting a model to my table but just 'changing a property' - if possible)?
2. Is there an easiest way of adding columns than what I did below? (e.g.: in C# I find very easy methods of adding columns at the end of a listView or after a column by index).

//'txt_n' is a textfield defining the number of columns I want to add when I click 'jButton1'
//table is my JTable
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        for(int i=1;i<=Integer.parseInt(txt_n.getText());i++)
              table.addColumn(new TableColumn(table.getColumnCount()-i));
7 Years
Discussion Span
Last Post by Clawsy
Featured Replies

Oh... I must admit I tried like this:

//doesn't work
table.addColumn(new TableColumn(table.getColumnCount()-i).setHeaderValue(Integer.toString(i)));

//this works and I tried it after your post :) 

Thanks :D. What about the second question? Any more ideas or the same as mine?

Edited by Clawsy: n/a


yeah, the version in line 2 fails because setHeaderValue returns null. Wouldn't it be useful if it returned "this"?
As for your second Q, no, i've no immediate ideas. Mind you, I have no idea what columns you are adding or why ...


Yes you're right :).
... I use this for applications like: populating from a database and inserting values for some 'Statistics and probabilistic' calculations. ->Every event has a probability associated with it (that's two rows table with 'n' possible events). So, after setting that values I should make a graphical representation of it.... stuff like that.

Thanks for help! Thread solved :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.