0

I have a table created using seesaw.swingx and i want to refresh the data in the rows of the table (or even clearing the entire table and giving new data to it will do). How do i achieve this, I know i might have to use table/table-model, but how do i give this table model to my current table?

my table is created as
(swingx/table-x :id :data-table :horizontal-scroll-enabled? true :model [:columns [{:key :first-name :text "First Name"} {:key :last-name :text "Last Name"}] :rows (get-data)]))

EDIT:

So this is my handler where i want to update my table

(defn- return-movie-handler
  [event]
  (let [root (seesaw/to-root event)
        table (seesaw/select root [:#data-table])]
        ;some code
        (seesaw/replace! root table (get-table-model))))))

and my get-table-model is

(defn- get-table-model
  []
  (seesaw.table/table-model :columns [{:key :first-name :text "First Name"}
                                      {:key :last-name :text "Last Name"}]
                            :rows (get-data)))

doing this i get an exception java.lang.IllegalArgumentException: No implementation of method: :make-widget* of protocol: #'seesaw.make-widget/MakeWidget found for class: seesaw.table.proxy$javax.swing.table.DefaultTableModel

Harsh Shah
  • 368
  • 3
  • 17

2 Answers2

0

you may use replace! , http://daveray.github.io/seesaw/seesaw.core-api.html#seesaw.core/replace!

(replace! Container Old widget Table Model)

Here is updated code I base on your code. I tested on my local ,works good.

(use 'seesaw.core)


(defn- get-table-model
  [a b]
  (seesaw.core/table :model [:columns [ :first-name :last-name] 
                             :rows [[ a  b]]]))

(def base_frame (frame :title "Base Frame" :content (vertical-panel :items [(border-panel :north (get-table-model "a" "b" ) :id :panel_id)])))

(show! base_frame)
(pack! base_frame)

(replace!  (select base_frame [:#panel_id])  (first (select base_frame [:<javax.swing.JTable>])) (get-table-model "C" "D")   )
Shawn Zhang
  • 1,680
  • 1
  • 12
  • 21
  • when i do this i get an exception `No implementation of method: :make-widget* of protocol: #'seesaw.make-widget/MakeWidget` – Harsh Shah Nov 27 '14 at 04:54
  • could you show your code ? I use replace! to update a Jtabel from seesaw, that function `replace!` will work – Shawn Zhang Nov 27 '14 at 04:56
  • I tried to pass in root in place of container, would that be the right way to do it, or should i find the immediate container of my table and pass in that? – Harsh Shah Nov 27 '14 at 04:56
  • in my case, I used an immediate container ( use `seesaw.core/select` to get that container ) – Shawn Zhang Nov 27 '14 at 04:57
  • I still get the same exception passing in my immediate container to the replace!, i have added my code(using root) to the question. – Harsh Shah Nov 27 '14 at 05:13
  • So the exception tells me that it cannot find the implementation for 'make-widget' method for javax.swing.table.DefaultTableModel – Harsh Shah Nov 27 '14 at 05:24
  • would it be possible for you to show me in code how you did it for your jtable? – Harsh Shah Nov 27 '14 at 05:53
0

It's a bit late, but you can also use (config! (select root [:#data-table]) :model new-model), having kept the model in an atom or using a generator function. Much simpler than (replace!) imo.

nnbz
  • 33
  • 1
  • 2
  • 7