Tree cell disapearing

Hi
I'm using Java 1.5.0.11
I'm trying to make my own tree cell renderer and editor : the goal is to add to the standard tree cell (icon + uneditable text) an icon to the left, to indicate a certain "state". The state can be change by clicking on it, showxing a JPopupMenu to select a new one.
In my proto, it works well, except that when I change one row, it is redrawn completely blank. I need to click on it again to have it appear.
Any idea on why?
Best regards

TreeSelector. java
package treeselectproto;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.AbstractAction;
import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.ScrollPaneConstants;
import javax.swing.tree.TreeCellEditor;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreePath;
public class TreeSelector {
     protected JTree itsTree;
     protected JScrollPane itsScrollPane;
     protected Map<Object, State> itsStates=new HashMap<Object, State>();
     protected CellRenderer itsRenderer;
     protected JPopupMenu itsPopupMenu = new JPopupMenu();
     public TreeSelector()
          itsTree=new JTree();
          itsRenderer=new CellRenderer();
          itsTree.setCellRenderer(itsRenderer);
          itsTree.setCellEditor(itsRenderer);
          itsTree.setEditable(true);
          buildScrollPane();
          List<State> theStates=State.getPopupStates();
          for(State s:theStates)
               PopupAction a=new PopupAction(s);
               JMenuItem mi=new JMenuItem(a);
               itsPopupMenu.add(mi);
     private void buildScrollPane() {
          itsScrollPane= new JScrollPane(itsTree,
                    ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
     public JScrollPane getScrollPane() {
          return itsScrollPane;
     @SuppressWarnings("serial")
     private  class CellRenderer extends AbstractCellEditor implements TreeCellRenderer, TreeCellEditor
          private JPanel itsPanel;
          private JLabel itsLabel;
          private JButton itsStateBtn;
          private BorderLayout itsLayout;
          public  CellRenderer()
               itsPanel=new JPanel();
               itsPanel.setLayout(itsLayout=new BorderLayout());
               itsPanel.setDoubleBuffered(false);
               itsLayout.setVgap(1);
               itsLayout.setHgap(1);
               itsLabel=new JLabel();
               itsLabel.setDoubleBuffered(false);
               itsPanel.add(itsLabel,BorderLayout.CENTER);
               itsStateBtn=new JButton(new AbstractAction(){
                    public void actionPerformed(ActionEvent aE) {
                         showPopup();
               itsStateBtn.setBorderPainted(true);
               itsStateBtn.setContentAreaFilled(false);
               itsStateBtn.setDoubleBuffered(false);
               itsPanel.add(itsStateBtn,BorderLayout.WEST);
          protected void showPopup() {
               itsPopupMenu.show(itsStateBtn, 0, 0);
          public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
               TreePath thePath=tree.getPathForRow(row);
               itsPanel.setBackground(tree.getBackground());
               if(thePath != null)
                    State theState=getStateForTreePath(thePath);
                    String ic=theState.getSign();
                    itsStateBtn.setText(ic);
               itsLabel.setText(value.toString());
               itsStateBtn.setPreferredSize(null);
               itsLabel.setPreferredSize(null);
               itsPanel.setBackground( selected? Color.lightGray:tree.getBackground());
               itsLayout.invalidateLayout(itsPanel);
               return itsPanel;
          private Object itsValue;
          public Component getTreeCellEditorComponent(JTree aTree, Object aValue, boolean aIsSelected, boolean aExpanded, boolean aLeaf, int aRow) {
               // if edting, it has the focus
               itsValue=aValue;
               return getTreeCellRendererComponent(aTree,aValue,aIsSelected,aExpanded,aLeaf,aRow,true);
          public Object getCellEditorValue() {
               return itsValue;
     public State getStateForTreePath(TreePath thePath) {
          State ret=itsStates.get(thePath.getLastPathComponent());
          if(ret==null)
               ret=State.defaultState();
          return ret;
     @SuppressWarnings("serial")
     private class PopupAction extends AbstractAction
          protected State itsState;
          public PopupAction(State aState) {
               super(aState.getLabel());
               itsState = aState;
          public void actionPerformed(ActionEvent aE) {
               TreePath thePath=itsTree.getEditingPath();
               Object theObj=thePath.getLastPathComponent();
               itsStates.put(theObj, itsState);
}

Similar Messages

  • How to display multiple JComponents in a tree cell renderer

    I have an object in a tree cell renderer and want to display its members(three members) status in a JTree as checkboxes such that each node displays three checkboxex with member-names and a node name. i tried using a JPanel and adding three labels into this panel to be returned for the cell renderer but the GUI fails to paint the node componnents. However on clicking the node the component which isn't visible displays correctly. please Help me out

    Since you didn't provide any sample code, it's all about wild guesses on what your problem is. The following code shows the type of program you could have posted :import javax.swing.*;
    import javax.swing.tree.*;
    import java.awt.*;
    public class TestTree extends JPanel {
         private static class MyCell {
              String theCellName;
              boolean theFirstField;
              boolean theSecondField;
              boolean theThirdField;
              public MyCell(String aName, boolean firstField, boolean secondField, boolean thirdField) {
                   theCellName = aName;
                   theFirstField = firstField;
                   theSecondField = secondField;
                   theThirdField = thirdField;
         private static class MyTreeCellRenderer extends JPanel implements TreeCellRenderer {
              private JLabel theCellNameLabel;
              private JCheckBox theFirstCheckBox;
              private JCheckBox theSecondCheckBox;
              private JCheckBox theThirdCheckBox;
              private DefaultTreeCellRenderer theDelegate;
              public MyTreeCellRenderer() {
                   super(new GridLayout(4, 1));
                   theCellNameLabel = new JLabel();
                   add(theCellNameLabel);
                   theFirstCheckBox = new JCheckBox("firstField");
                   add(theFirstCheckBox);
                   theSecondCheckBox = new JCheckBox("secondField");
                   add(theSecondCheckBox);
                   theThirdCheckBox = new JCheckBox("thirdField");
                   add(theThirdCheckBox);
                   theDelegate = new DefaultTreeCellRenderer();
                   setOpaque(true);
              public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
                                                                       boolean expanded, boolean leaf, int row, boolean hasFocus) {
                   if (!(value instanceof DefaultMutableTreeNode)) {
                        return theDelegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
                   Object userObject = ((DefaultMutableTreeNode)value).getUserObject();
                   if (!(userObject instanceof MyCell)) {
                        return theDelegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
                   setBackground(tree.getBackground());
                   if (selected) {
                        setBorder(BorderFactory.createLineBorder(Color.BLUE, 2));
                   } else {
                        setBorder(BorderFactory.createLineBorder(getBackground(), 2));
                   MyCell cell = (MyCell)userObject;
                   theCellNameLabel.setText(cell.theCellName);
                   theFirstCheckBox.setSelected(cell.theFirstField);
                   theSecondCheckBox.setSelected(cell.theSecondField);
                   theThirdCheckBox.setSelected(cell.theThirdField);
                   return this;
              public Component add(Component comp) {
                   if (comp instanceof JComponent) {
                        ((JComponent)comp).setOpaque(false);
                   return super.add(comp);
         public TestTree() {
              super(new BorderLayout());
              JTree tree = new JTree(createModel());
              tree.setShowsRootHandles(true);
              tree.setCellRenderer(new MyTreeCellRenderer());
              add(new JScrollPane(tree), BorderLayout.CENTER);
         private static final TreeModel createModel() {
              DefaultMutableTreeNode root = new DefaultMutableTreeNode(new MyCell("root", true, true, true));
              DefaultMutableTreeNode child1 = new DefaultMutableTreeNode(new MyCell("child1", false, true, false));
              DefaultMutableTreeNode child2 = new DefaultMutableTreeNode(new MyCell("child2", false, false, true));
              root.add(child1);
              root.add(child2);
              return new DefaultTreeModel(root);
         public static void main(String[] args) {
              final JFrame frame = new JFrame("Test");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setContentPane(new TestTree());
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        frame.setSize(600, 400);
                        frame.show();
    }

  • Focus Lost on Tree Cell Edit

    I am trying to force changes made in a tree cell edit when focus to that tree node has been lost(like on an enter button press) but it always reverts to the old value. i have tried adding a CellEditorListener to force an enter key press on the editingCanceled action but this still reverts the value.
    Anyone have any ideas on how to fix this?
    Thanks.

    Hi,
    Try to use
        call method cl_gui_control=>set_focus exporting control = grid1.

  • Editing non-tree cells problem in JTreeTable

    Hello all,
    I've been playing around with the JTreeTable for quite a while and have a fairly good grip on it. However, I've run into a problem that involves the display of cell data in the non-tree cells.
    Assume I have a JTreeTable with one node below the root (and the root node is not displayed). Also assume I've edited some information in one of the other cells in a 5-celled JTreeTable. The JTreeTable behaves normally with regard to editing/setting the values of the table cells.
    Now, with the click of a separate button, I programmatically create a new node in the JTree. I update the JTree model with a call to nodeChanged() and nodeStructureChanged() (or I could call reload() - both seem to work).
    This successfully adds a node, but in the process clears the entire remainder of the table's cell values. If I call fireTableDataChanged(), then the display of the JTree gets all screwed up (basically what happens to the display if you add/remove nodes, but don't update the display in a JTree). Not only that, but the fireTableDataChanged() method still does not redisplay my cell information for the remainder of the table.
    I'm at a loss to figure out what's responsible for this. The tableCellRenderer seems to work just fine until I add node. Even then, the tableCellRenderer for the JTree still works until I call fireTableDataChanged().
    Any ideas?
    Thank you,
    Brion Swanson

    I use a JTreeTable and in looking at my code, I've
    noticed that I make use of treeTable.repaint() fairly
    frequently (as whenever I update my stuff).Did the treeTable.updateUI do funky things to your JTree? It does on mine if I do a programmatic node addition or removal (basically any change to the tree structure will cause treeTable.updateUI() to completely destroy the display of the tree). This is a separate issue, but I thought I'd ask anyway since you seem to have run into at least a few of the same problems I'm experiencing.
    I don't fully understand your problem<snip/>
    do you mean
    it drops all edits you have done?Yes, it drops all the edits except the one currently being "edited" (that is, the selected editable cell will not lose it's value).
    I had a problem about it dropping the edits I had
    done and I resolved them by adding key listeners
    and played with the TableCellEditor.Could you elaborate on what you did to the TableCellEditor and which object you had listening to the keys (the table? or the tree? or something else?).
    You help is greatly appreciated!
    Brion Swanson

  • TextFormatter in list, table and tree cells

    Release 8u40 introduces the TextFormatter concept in the text input field area. It is currently a new property of the TextInputControl class.
    This is defintely a more elegant way to deal with validation than overriding "replaceText(...)".
    Shouldn't this property also be available in list, table and tree cells ?
    Are there plans to do this (before we make our own implementation) ?

    I've got exactly the same problem, +1.
    This shouldn't be to difficult to solve for 8u60 and definitely useful,
    giving access to the text input control in mutable cells could be a one-line workaround !
    Additionally, could a TextFormatter be made shareable between table/list rows
    by NOT using the value/valueConverter properties, but only the filter part in cases
    where the final desired output type is String ?

  • Tree Cell Renderer settings for displaying complete text.

    I have a tree model. It is of the form
    abc (123.00)
    -----def (456.00)
    ----------ghi (678.00)
    But it is displayed like
    abc (12...
    -----def (45..
    ----------ghi (67..
    I don't want the numbers in the end to be missing. It is a problem for the user to expand them everytime.
    I am using, JTree and using my cell renderer, with following properties in
    super.getTreeCellRendererComponent(tree, false, X, false, false, row, false);I did try to change it to
    super.getTreeCellRendererComponent(tree, false, X, TRUE, false, row, false);but still no success.
    My function toString() for tree elements looks like this
                     double u = "123.00";
                     String num = String.format("%.2f", u);
                     return getName() + " (" + num  + ")";Can you please suggest possible way around for this?

    package abc;
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.WindowConstants;
    import javax.swing.JFrame;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.TreeSelectionModel;
    public class NewJPanel extends javax.swing.JPanel implements MouseListener {
         public static void main(String[] args) {
              JFrame frame = new JFrame();
              frame.getContentPane().add(new NewJPanel());
              frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
              frame.pack();
              frame.setVisible(true);
         JTree m_tree;
        private JScrollPane myPane;
        float multi = 1;
        DefaultTreeModel tree = new DefaultTreeModel(new ContainerNode("root"));
        DefaultMutableTreeNode parent = (DefaultMutableTreeNode)tree.getRoot();
         public NewJPanel() {
            super(new BorderLayout());
            String util = String.format("%.2f", 123456789012345679801234567980.00);
            util = "abc" + " (" + util  + ")";
                DefaultMutableTreeNode e = new DefaultMutableTreeNode(util);
                tree.insertNodeInto(e, parent, 0);
            m_tree = new JTree(tree);
            m_tree.setEditable(false);
            m_tree.setDragEnabled(false);
            m_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.CONTIGUOUS_TREE_SELECTION);
            m_tree.setAutoscrolls(true);
            m_tree.setPreferredSize(new java.awt.Dimension(397, 297));
            myPane = new JScrollPane(m_tree);
            myPane.setAutoscrolls(true);
            myPane.getVerticalScrollBar().setAutoscrolls(true);
            add(myPane, BorderLayout.CENTER);
            m_tree.addMouseListener(this);
              initGUI();
         private void initGUI() {
              try {
                   setPreferredSize(new Dimension(400, 300));
              } catch (Exception e) {
                   e.printStackTrace();
         public void mouseClicked(MouseEvent e) {
              String util = String.format("%f", 6546464642345679801234567980.00 * multi);
            util = "abc" + " (" + util  + ")";
            DefaultMutableTreeNode child = (DefaultMutableTreeNode) parent.getChildAt(0);
            child.setUserObject(util);
            m_tree.repaint();
         public void mouseEntered(MouseEvent e) {}
         public void mouseExited(MouseEvent e) {}
         public void mousePressed(MouseEvent e) {}
         public void mouseReleased(MouseEvent e) {}
    class ContainerNode extends DefaultMutableTreeNode
        private static final long serialVersionUID = 14;
        ContainerNode(String s)
        { super(s); }
    }Executing this code... clicking in the panel, changes the number.
    The new number is displayed as (65464646423456798000000000.000.......
    My problem is nearly similar, except that in my code I am using, String.format("%.2f", 6546464642345679801234567980.00 * multi);
    and still I get (65...)

  • Tree Cell Editorer

    I have a problem with editing a cell in a tree
    I implemented the TreeCellEditorer
    public Component getTreeCellEditorComponent(JTree arg0, Object value, ...){
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
        Object userObject = node.getUserObject();
        if (userObject instanceof OverLay)
            return ((OverLay) userObject).getComponent();  // return a JPanel
        return new JLabel(userObject.toString());  // return the String
    public boolean isCellEditable(EventObject arg0) {
         return true;
    }I also set the tree editable property to true
    tree.setEditable(true);
    basiaclly, the line of code:
    return ((OverLay) userObject).getComponent();  // return a JPanelreturns a JPanel, and this panel contains 3 JCheckBox, and JLabels
    i cannot check or uncheck the JCheckBox. How can i fix this?

    my fault.
    I had the setEditable(false) on the JCheckBox.

  • I need to change tree cell render on particular node when it is selected.

    actually the treecell change its icon when it is selected. yhe other cell doesnot changed its icon

    Write your own renderer or extends DefaultTreeCellRenderer. Add something like this to the method
    Component getTreeCellRendererComponent(JTree tree,
                                           Object value,
                                           boolean selected,
                                           boolean expanded,
                                           boolean leaf,
                                           int row,
                                           boolean hasFocus)
        if (selected)
           set the icon to be special icon
        else
           set the icon back to normal
    }

  • JTreeTable: can't get CellEditor for non-tree cells to work

    Hi!
    I'm using a JTreeTable ( http://java.sun.com/products/jfc/tsc/articles/treetable2/index.html ) in my application. In the table cells I use ImageIcons to visualize some object data. Now I need some interaction when the user clicks on these icons, but I'm not able to get any kind of cell editor to work with the table's cells.
    I now play around with the TreeTable 2 example code and it's about the same. I can't even get a JTextField to work as an editor. I've been searching this forum and the web but did not find an appropriate solution or sample code.
    Is someone out there who can help me out?

    Hi there.
    Hopefully we can help each other out as I am also struggling with the example from sun.
    I have managed to get an editor to work but I'm using a check box.
    Very simple, I took all the code from sun. In the TreeTableModelAdapter, I put code for isCellEditable() and for setValueAt(), like this
    public boolean isCellEditable(int row, int column) {
             if(column ==0){        
                  return treeTableModel.isCellEditable(nodeForRow(row), column);
             else if(column == 1){        
                  return true;
             else return false;          
        public void setValueAt(Object value, int row, int column) {
              if(column ==0){
                   treeTableModel.setValueAt(value, nodeForRow(row), column);
              else if(column == 1){
                   DefaultMutableTreeNode theNode = (DefaultMutableTreeNode)nodeForRow(row);
                   NewsNode theNewsNode = (NewsNode)theNode.getUserObject();
                   if(!theNewsNode.isSelectable()) return;
                   Boolean theValue = (Boolean)value;               
                   theNewsNode.setSelected(theValue.booleanValue());
                 fireTableChanged(null);
        }I'm not sure if that's what you need but it worked for me.
    Maybe you could elaborate further.
    Cheers,
    rachel

  • Table cells disapear at bottom of page

    Hi, I am trying to set up a page with APs tables and cells
    and all goes well until I insert information into my center cell
    and then for some reason the copyright on the bottom of the page
    dissapears and no matter how much space I give the table above it,
    it does not help. It seems like instead of pushing the bottom table
    down, it is resting on top of it. And covering the info. Does
    anyone know what the problem might be?
    Thanks

    The first thing you have to wrap your brain around is that
    it's just HTML.
    There is no such thing as a "DW table". It's just an HTML
    table. If it's
    all over the place it's because that is what *your* HTML
    tells the browser
    to do.
    > I thought DW would give me the same with library items
    It will in a fashion, yes.
    > that is why I am using Absolute Positioning with the
    tables
    Don't even think of doing it this way.
    > DW is squirrelly
    Let's just say that your methods are producing squirrelly
    HTML. I can see
    that you are using Layout mode, and that's the squirrely
    part. Please don't
    use this. And yes, it does produce exceptionally fragile
    HTML, which is why
    it has been completely removed from DW CS4.
    Also, you have improperly created your Library item -
    <body>
    <table width="989" border="0" cellpadding="0"
    cellspacing="0">
    <!--DWLayoutTable-->
    <tr>
    <td height="110" colspan="3" valign="top"><!--
    #BeginLibraryItem
    "/Library/nbs_banner.lbi" -->
    <style type="text/css">
    <!--
    body {
    You cannot have an embedded stylesheet in a Library item. It
    will be
    ignored when the Library item is inserted in the parent page.
    Can you post a link to the uploaded page so we can see the
    entire page and
    its code (the code is truncated for us reading/replying from
    the NNTP
    forums)? And can you please describe for us what you are
    trying to achieve?
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "wen8" <[email protected]> wrote in message
    news:[email protected]...
    >I am new to DW can you tell? :) I'm used to using shared
    borders in Front
    > page. I thought DW would give me the same with library
    items. DW tables
    > seem
    > to go all over the place, this is why I am using
    Absolute Positioning with
    > the
    > tables. I have used tables for my layout for years with
    an old version of
    > netscape composer without this frustration. DW is
    squirrelly. I have
    > attached
    > code but the message says "If you would like to insert
    raw code into your
    > message insert it here, the html code will be stripped
    out, and spaces
    > will be
    > replaced with HTML spaces ( ) " So I don't know
    how it will turn
    > out.
    >
    >

  • Editing a Tree Cell

    Hi All,
    I know that many questions crop up in this area; I will try to be brief.
    My class extends JTextField and implements TreeCellEditor. I defined these methods:
    1. addCellEditorListener
    2. isCellEditable
    3. getTreeCellEditorComponent
    4. shouldSelectCell
    5. getCellEditorValue
    6. cancelCellEditing
    7. stopCellEditing
    8. removeCellEditorListener
    Numbers 2,3,4 make sense to me. They seem to say "if the cell is editable, then get its editor component, and decide if the whole cell should be selected when placed into edit." These work as I expected.
    But I also observe - and do not understand - this behavior:
    1. click inside a cell to edit it
    2. type something to change its content and hit the ENTER key
    When I do this, nothing happens. That is, the text cursor remains positioned within the cell. I found this strange because before I defined my own cell editor, I am fairly certain that the default editor responded to the enter key by removing the cell from edit mode.
    Stranger still is this: if, after editing a cell, I remove focus from it, e.g., I click on another cell, the first cell reverts to its former value. This is most frustrating. In this case, unlike the enter key case, I believe that getCellEditorValue is called. My understanding is that this method gets called when an edit is viewed as complete. Hence I return the current value of the cell. Some tracing shows that I am returning the proper value. Yet the cell reverts to its original, pre-edit value.
    So I guess I have two questions:
    1. what is "normative" in the "edit cycle", i.e., how is editing customarily terminated? Related to this is the disposition of the text cursor after edit. I prefer it not to remain in the edited field.
    2. Why does losing focus after edit cause my edited field to revert to its pre-edit value?
    As always, I am grateful for whatever light you can shed on these matters.
    Cordially,
    Paul

    It is a good thing you are learning how to use the TreeCellEditor interface but if you are doing something more than just learning then I would advice you use the DefaultCellEditor class instead. also if you desire to implement your own TreeCellEditor then, take time to take a look at the source code for your DefaultCellEditor class you should see what you are doing wrong and what they did right. The source code is in "JDKdir/src.zip"
    ICE

  • Tree Cell Renderer

    is there anyone who knows or can point me to some explanation
    on how to place a background image inside the tree??
    i'm trying to place different images for in behind the text
    and icons for each state, open and close.
    any info would be appreciated.
    thanks...

    You will need to specify an itemRenderer for your tree.
    Probably the easiest thing to do is to create an Actionscript
    itemRenderer that extends the current TreeItemRenderer. In your
    renderer, you can override the updateDisplayList function to allow
    for a background image depending on your data.
    Here is a skeleton of what your itemRenderer might look like:
    package
    import mx.controls.treeClasses.*;
    import mx.collections.*;
    public class MyTreeItemRenderer extends TreeItemRenderer
    public function MyTreeItemRenderer()
    super();
    override protected function
    updateDisplayList(unscaledWidth:Number,
    unscaledHeight:Number):void
    super.updateDisplayList(unscaledWidth, unscaledHeight);
    if(super.data)
    //Add your code here to add an image to the background of
    this item

  • Tree cell renderer shows (...) for long texts

    I know that the BasicTreeUI saves a cache but I don't know how to reset this cache, or if there is another solution
    Best regards
    Dekel

    My tree is inside jscrollpane.Ok, then I don't understand why your renderer truncates the displayed text.
    how can I set the jlabel prefered size to be in the
    exact width of the String ?AFAIK, this is the default behavior, i.e. you do not do anything.
    (I don't want to see a gap between the label and the end of the
    string when a node is selected)Uhm, I have no idea what "gap" you are talking about. I don't see any "gaps" when I select nodes in a JTree.

  • Tree Cell Renderer Highlight

    I have implemented a cutom renderer for my JTree that displays different icons for different types of data. However I cannot get the highlight color to work at all. Before using my custom renderer, the nodes would highlight when selected or being dragged over on and drag and drop operation. Now I cannot get this type of behavior. I attempted using the setBackground() method to set the color according to the "sel" flag that gets passed in to the getTreeCellRendererComponent method. Any advice would be appreciated.

    I have implemented a cutom renderer for my JTree that displays different icons for different types of data. However I cannot get the highlight color to work at all. Before using my custom renderer, the nodes would highlight when selected or being dragged over on and drag and drop operation. Now I cannot get this type of behavior. I attempted using the setBackground() method to set the color according to the "sel" flag that gets passed in to the getTreeCellRendererComponent method. Any advice would be appreciated.

  • How to get the table/tree/list cell underneath the mouse

    I feel like I must be missing something. How can I find out the tree cell underneath the mouse cursor?
    I am implementing drag and drop from a table to a tree. I need to know which tree cell the user dropped the item on. I can get the drop coordinates (in pixels, I assume) from the drag event, but there doesn't seem to be a way to convert that into the particular cell index. This same question applies to getting the list and table cell under at particular coordinates.
    If there isn't an API for this, has anyone found a reliable workaround (dividing Y by cell height, etc.)
    Thanks,
    Josh

    You need to put event handlers for the D&D events on the Cells that are being created (so you will need to set a custom cell factory). For example, every cell is a Node, and these support properties like 'onDragDroppedProperty', and 'onDragExitedProperty'.
    When you add event handlers to these, you should be notified of items being dragged onto specific Cells of the Tree. A Cell then can be matched with a particular item in the Tree by reading its TreeItem property.
    Also read the documentation for TreeItem. There is a bit there that says:
    "It is important to note however that a TreeItem is not a Node, which means that only the event types defined in TreeItem will be delivered. To listen to general events (for example mouse interactions), it is necessary to add the necessary listeners to the cells contained within the TreeView (by providing a cell factory)."
    Which gives a clear hint at the end that for other interactions, you should add listeners to the Cells.
    Good luck!

Maybe you are looking for