Binding BasicDataset to JTable

Getting better at figuring out this side of things, but still could use a hand.

What is the best way to bind the dataset in the properties to a JTable? If I use placeholder data in the component, it will draw, but I can’t get anything to appear using the property I created. It also doesn’t seem to redraw when I change that property, but I think I know how to fix that once I can verify that the binding is working property.

Thanks for any help in advance.

So I found a way to make the binding and to get the table to update(though not the best route). But now I’ve been struggling with a new odd issue. I’ll post my setData code below, but somehow its taking the dataset and transposing the data in the table. I’ve spent a bit too much time struggling on this, so any help or pointers are appreciated.

    public void setData(Dataset Data){
        data = Data;
        this.bData= new BasicDataset(data);
        model = new DefaultTableModel(bData.getData(), bData.getColumnNames().toArray());

What does this mean, exactly? Rows/columns are flipped?

Correct. Though the headers have the correct values.

If I print the number of rows of data and bData, I get the value I’d expect, but as soon as it goes to the table model, the values swap.

Where is your source dataset, that’s passing into setData coming from? I suspect something about the construction of your underlying dataset is at fault, though I’m not sure what it would be, to be honest.

Its a property in the designer. It displays the correct way if I open the Dataset viewer there.

Try dropping the model.fireTableStructureChanged(); line.

Still displaying transposed. :confused:

Attached is a screenshot of what I’m seeing in case it helps. Top is the default table, bottom is my component. I set up a binding from my dataset to the test data in the first table.


BasicDataset stores its data column-first, DefaultTableModel uses row-first.

1 Like

Use a DatasetTableModel instead.

1 Like

That was it. Thanks a ton. Just starting to get my feet wet with the SDK stuff. Didn’t think to check if there was a TableModel built for the Dataset Type.

1 Like