# Binding BasicDataset to JTable

**URL:** <https://forum.inductiveautomation.com/t/binding-basicdataset-to-jtable/22923>\
**Category:** Module Development\
**Created:** [February 27, 2019, 1:25pm UTC](https://forum.inductiveautomation.com/t/binding-basicdataset-to-jtable/22923 "2019-02-27T13:25:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [February 27, 2019, 1:25pm UTC](https://forum.inductiveautomation.com/t/binding-basicdataset-to-jtable/22923/1 "2019-02-27T13:25:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [March 1, 2019, 7:14pm UTC](https://forum.inductiveautomation.com/t/binding-basicdataset-to-jtable/22923/2 "2019-03-01T19:14:17Z")

</div>

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.

```auto
    public void setData(Dataset Data){
        data = Data;
        this.bData= new BasicDataset(data);
        model.fireTableStructureChanged();
        model = new DefaultTableModel(bData.getData(), bData.getColumnNames().toArray());
        jt.setModel(model);
    }

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 1, 2019, 7:17pm UTC](https://forum.inductiveautomation.com/t/binding-basicdataset-to-jtable/22923/3 "2019-03-01T19:17:40Z")

</div>

> [@grietveld](#):
>
> somehow its taking the dataset and transposing the data in the table.

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

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [March 1, 2019, 7:19pm UTC](https://forum.inductiveautomation.com/t/binding-basicdataset-to-jtable/22923/4 "2019-03-01T19:19:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 1, 2019, 7:21pm UTC](https://forum.inductiveautomation.com/t/binding-basicdataset-to-jtable/22923/5 "2019-03-01T19:21:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [March 1, 2019, 7:23pm UTC](https://forum.inductiveautomation.com/t/binding-basicdataset-to-jtable/22923/6 "2019-03-01T19:23:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 1, 2019, 7:30pm UTC](https://forum.inductiveautomation.com/t/binding-basicdataset-to-jtable/22923/7 "2019-03-01T19:30:23Z")

</div>

Try dropping the `model.fireTableStructureChanged();` line.

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [March 1, 2019, 7:35pm UTC](https://forum.inductiveautomation.com/t/binding-basicdataset-to-jtable/22923/8 "2019-03-01T19:35:31Z")

</div>

Still displaying transposed. 😕

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.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/b/beca3285d741ea1e57251d31e0c6168f31359ef1.png)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 1, 2019, 7:55pm UTC](https://forum.inductiveautomation.com/t/binding-basicdataset-to-jtable/22923/9 "2019-03-01T19:55:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 1, 2019, 7:57pm UTC](https://forum.inductiveautomation.com/t/binding-basicdataset-to-jtable/22923/10 "2019-03-01T19:57:00Z")

</div>

Use a `DatasetTableModel` instead.

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [March 1, 2019, 8:07pm UTC](https://forum.inductiveautomation.com/t/binding-basicdataset-to-jtable/22923/11 "2019-03-01T20:07:32Z")

</div>

> [@Kevin.Herron](#):
>
> BasicDataset stores its data column-first, DefaultTableModel uses row-first.

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.
