Thanks for the help! The code comes from the Java tutorials at http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#headertooltip
which compiles and runs as advertised on my system. Here's an attempt to use it in clojure, which does display the table correctly, but the prn inside 'createDefaultTableHeader' never gets called. How can I debug this? ----------------------------------------- (import '(javax.swing JTable JFrame JPanel SwingUtilities JScrollPane) '(javax.swing.table AbstractTableModel JTableHeader) '(java.awt BorderLayout)) (defn my-table "cols is a seq of form ((\"Name\" String) (\"Married?\" Boolean)...) row-count-proc is a 0-ary proc which returns the number of data rows. get-value-at-proc is 2-ary proc (row col) which returns value. set-value-at-proc (optional) is a 3-ary proc (val row col) which sets value. if nil, table is not editable. Returns a content pane." [cols row-count-proc get-value-at-proc & set-value-at-proc] (let [col-names (map first cols) col-classes (map second cols) model (proxy [AbstractTableModel] [] (getColumnCount [] (count cols)) (getRowCount [] (row-count-proc)) (isCellEditable [row col] set-value-at-proc) (getColumnName [col] (nth col-names col)) (getValueAt [row col] (get-value-at-proc row col)) (setValueAt [val row col] (set-value-at-proc val row col)) (getColumnClass [col] (nth col-classes col))) tbl (proxy [JTable] [model] (createDefaultTableHeader [] (let [column-model (proxy-super getColumnModel)] (prn 'createDefaultTableHeader) (proxy [JTableHeader] [column-model] (getToolTipText [evt] (let [p (.getPoint evt) index (.getColumnIndexAtX column-model (.x p)) real-index (-> column-model (.getColumn index) .getModelIndex)] (nth col-names real-index))))))) pn (JPanel.)] (.setLayout pn (BorderLayout.)) (.add pn (.getTableHeader tbl) BorderLayout/PAGE_START) (.add pn (JScrollPane. tbl)) (.setOpaque pn true) pn)) (SwingUtilities/invokeLater (proxy [Runnable] [] (run [] (let [frame (JFrame. "Demo") tbl (my-table [["A" String] ["B?" Boolean]] (fn [] 5) ; row-count-proc (fn [r c] (if (= c 0) "OK" true)))] ; get-value-at-proc (doto frame (.setContentPane tbl) .pack .show))))) On Feb 11, 4:33 pm, Meikel Brandmeyer <m...@kotka.de> wrote: > Hi, > > Am 11.02.2009 um 23:08 schrieb what-a-guy: > > > > > How would I code the following in clojure? > > > JTable table = new JTable(new MyTableModel()) { > > ... > > > //Implement table header tool tips. > > protected JTableHeader createDefaultTableHeader() { > > return new JTableHeader(columnModel) { > > public String getToolTipText(MouseEvent e) { > > String tip = null; > > java.awt.Point p = e.getPoint(); > > int index = columnModel.getColumnIndexAtX(p.x); > > int realIndex = > > columnModel.getColumn(index).getModelIndex(); > > return columnToolTips[realIndex]; > > } > > }; > > } > > }; > > I'm not sure about the Java notation. So this may > be completely wrong. I'm also assuming, that > column-model and such things are defined somewhere > around this snippet. > > (proxy [JTable] [(MyTableModel.)] > (createDefaultTableHeader > [] > (proxy [JTableHeader] [column-model] > (getToolTipText > [evt] > (let [p (.getPoint evt) > index (.getColumnIndexAtX column-model (.x p)) > real-index (-> columnModel > (.getColumn index) > .getModelIndex)] > (nth column-tool-tips real-index)))))) > > Sincerely > Meikel > > smime.p7s > 5KViewDownload --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---