From: John B. Matthews on 21 Sep 2009 12:09 In article <6d9a11f6-73e4-4cb0-9598-02444be92ecd(a)j9g2000vbp.googlegroups.com>, Hole <h0leforfun(a)gmail.com> wrote: > I would like to get the reference of a component (in my case is a > JCheckbox) and call the setVisible method on it. I tried to do it > with getTableCellEditorComponent/ getTableCellRendererComponent but > it doesn't work properly: it seems that the property is being set on > every component of the column. I think this is expected. You may want to review the tutorial's "Concepts: Editors and Renderers" for more detail: <http://java.sun.com/docs/books/tutorial/uiswing/components/table.html #editrender> Instead, why not just query the JTable's data model? -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews>
From: Hole on 22 Sep 2009 03:40 > Hole <h0lefor...(a)gmail.com> wrote: > > I would like to get the reference of a component (in my case is a > > JCheckbox) and call the setVisible method on it. I tried to do it > > with getTableCellEditorComponent/ getTableCellRendererComponent but > > it doesn't work properly: it seems that the property is being set on > > every component of the column. > > I think this is expected. You may want to review the tutorial's > "Concepts: Editors and Renderers" for more detail: > > <http://java.sun.com/docs/books/tutorial/uiswing/components/table.html > #editrender> Well, I guess I need it, even if I thought there was a direct way to obtain the rendered widget's reference. > > Instead, why not just query the JTable's data model? > If I query data model, I get the value of the column (a boolean false or true) while I cannot get the single component rendered in the cell (to call the setVisible() method), can I? I need to set properties on rendered widgets on a cell basis, under certain conditions found in other cells (in previous rows).
From: John B. Matthews on 22 Sep 2009 13:29 In article <f1d2daf1-e718-472e-a7e6-d716d83fff5f(a)p36g2000vbn.googlegroups.com>, Hole <h0leforfun(a)gmail.com> wrote: > > Hole <h0lefor...(a)gmail.com> wrote: > > > I would like to get the reference of a component (in my case is a > > > JCheckbox) and call the setVisible method on it. I tried to do it > > > with getTableCellEditorComponent/ getTableCellRendererComponent > > > but it doesn't work properly: it seems that the property is being > > > set on every component of the column. > > > > I think this is expected. You may want to review the tutorial's > > "Concepts: Editors and Renderers" for more detail: > > > > <http://java.sun.com/docs/books/tutorial/uiswing/components/ table.html#editrender> > > Well, I guess I need it, even if I thought there was a direct way to > obtain the rendered widget's reference. Yes. In particular, there is no "rendered widget". As explained in the tutorial, "Swing tables are implemented differently." > > Instead, why not just query the JTable's data model? > > > If I query [the] data model, I get the value of the column (a boolean > false or true) while I cannot get the single component rendered in > the cell (to call the setVisible() method), can I? As noted in the tutorial, there is no individual component for each cell; there is a component that is used to render each cell in a column based on the value obtained from the data model for each row in that column. > I need to set properties on rendered widgets on a cell basis, under > certain conditions found in other cells (in previous rows). If the values in a column have dependencies, adjust them in your data model's setValueAt() method. If the appearance of cells in a column have dependencies, implement your own renderer, giving it knowledge of the those dependencies. If you extend AbstractTableModel, as outlined in the tutorial, you can fire the appropriate notification to update any dependent cells. In that way, inter-dependent cells will be updated automatically when any one is changed. As you haven't specified the dependencies, an SSCCE would be helpful: <http://pscode.org/sscce.html> -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews>
From: Hole on 23 Sep 2009 05:53 > > > I need to set properties on rendered widgets on a cell basis, under > > certain conditions found in other cells (in previous rows). > > If the values in a column have dependencies, adjust them in your data > model's setValueAt() method. > > If the appearance of cells in a column have dependencies, implement your > own renderer, giving it knowledge of the those dependencies. > > If you extend AbstractTableModel, as outlined in the tutorial, you can > fire the appropriate notification to update any dependent cells. In that > way, inter-dependent cells will be updated automatically when any one is > changed. Many thanks, John. At the end I've realized how the renderer works and tried to implement my own. Now it "works" but: 1. setVisible on checkbox doesn't work (but with setEnabled(false) and setOpaque(true) got sense) 2. when you sort the table the relation is being lost, since the not enabled checkbox cells don't move togheter with the others. Actually, what I really need is a "rowspannable" JTable - where one checkbox cell is shared with rows having a same value in a cell - ...with a correct behaviour for sorting (I've found this SWT component http://agilegrid.sourceforge.net/ but I use Swing and I don't know it it's possible to use Swing and SWT togheter without conflicts). Also, I've found this tutorial: http://www.swingwiki.org/howto:column_spanning that could be useful. Now I'll check if implementing an AbstractTableModel works for me. Thanks again for your clear answer!!! > > As you haven't specified the dependencies, an SSCCE would be helpful: > > <http://pscode.org/sscce.html> > > -- > John B. Matthews > trashgod at gmail dot com > <http://sites.google.com/site/drjohnbmatthews>
From: John B. Matthews on 23 Sep 2009 17:51 In article <80626764-6b7e-4f96-bbd5-5d19cf3f33ea(a)p23g2000vbl.googlegroups.com>, Hole <h0leforfun(a)gmail.com> wrote: > At the end I've realized how the renderer works and tried to > implement my own. Now it "works" but: > > 1. setVisible on checkbox doesn't work (but with setEnabled(false) and > setOpaque(true) got sense) I see this. Alternatively, one may return any desired component, even null, to achieve various effects. > 2. when you sort the table the relation is being lost, since the not > enabled checkbox cells don't move togheter with the others. I often sort in the data model, despite the required coordinate transformation, using a custom Comparator; but I see that Java 1.6 added setRowSorter() to JTable, and DefaultRowSorter permits setComparator(). [Interesting span examples...] > Now I'll check if implementing an AbstractTableModel works for me. Recalling a time when I was somewhat recalcitrant in this area, I can only advocate it, now. > Thanks again for your clear answer!!! You're welcome. -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews>
|
Pages: 1 Prev: License Next: Some projects were hidden because they exist in the workspace directory |