Problem with JTree editing icons

Hello,
I want to edit another icons than the default icons in JTree object.
I look in the javadoc at the several methods, but I do not find a method witch can give me the possibility to setup the collapsed and expanded icon.
If some one now how to do that, it will be cool.
Thanks.

I write this class :
public class SampleTreeCellRenderer extends TreeCellRenderer
/** Font used if the string to be displayed isn't a font. */
static protected Font defaultFont;
/** Icon to use when the item is collapsed. */
static protected ImageIcon collapsedIcon;
/** Icon to use when the item is expanded. */
static protected ImageIcon expandedIcon;
/** Color to use for the background when selected. */
static protected final Color SelectedBackgroundColor=Color.yellow;
static
     try {
     defaultFont = new Font("SansSerif", 0, 12);
} catch (Exception e) {}
     try {
     collapsedIcon = new ImageIcon("images/collapsed.gif");
     expandedIcon = new ImageIcon("images/expanded.gif");
     } catch (Exception e) {
     System.out.println("Couldn't load images: " + e);
public SampleTreeCellRenderer() {
super();
public SampleTreeCellRenderer(String collapsedImagePath,String expandedImagePath) {
super();
     try {
     if (collapsedImagePath!=null) collapsedIcon = new ImageIcon(collapsedImagePath);
     if (expandedImagePath!=null) expandedIcon = new ImageIcon(expandedImagePath);
     } catch (Exception e) { System.out.println("Couldn't load images: " + e); }
public void setCollapsedIcon(String path) {
try {
if (path!=null) collapsedIcon=new ImageIcon(path);
} catch (Exception e) { System.out.println("Couldn't load images: " + e); }
public void setExpandedIcon(String path) {
try {
if (path!=null) expandedIcon=new ImageIcon(path);
} catch (Exception e) { System.out.println("Couldn't load images: " + e); }
/** Whether or not the item that was last configured is selected. */
protected boolean selected;
public Component getTreeCellRendererComponent(
JTree tree, Object value,     
boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
     Font font;
     String stringValue = tree.convertValueToText(value, selected,expanded,leaf,row,hasFocus);
     /* Set the text. */
     setText(stringValue);
     /* Tooltips used by the tree. */
     setToolTipText(stringValue);
     /* Set the image. */
     if(expanded) { setIcon(expandedIcon); }
     else if(!leaf) { setIcon(collapsedIcon);}
else { setIcon(null);}
     /* Update the selected flag for the next paint. */
     this.selected = selected;
     return this;
public void paint(Graphics g) {
     super.paint(g);
} // end of class SampleTreeCellRenderer
I test it but I do not understand why it do not display the icons.

Similar Messages

  • Problem with local editing after update to SP13

    Hallo,
    we have updated our Enterprise Portla 7.00 to SP13. Now many user have Problem with local editing. The error message is "The download of the document fail".
    I know that every PC needs the "Docservice" Active X component installed. The "Docservice" is also installed.
    At my PC theres only this problem with "html" documents.
    What could be the problem. ?
    Please help.
    Many thanks
    Ronald

    We found that there is a problem with the Docservice Active X Component.
    If we work in a deeper folder there is a problem with the length of the url. I changed the TEMP Setting
    "Setting a different TEMP directory:                                     
    In cases that it is problematic to use the standard %TEMP% directory,   
    setting the environment variable SAPKM_USER_TEMP pinpointing to a       
    corresponding directory path (e.g.                                      
    X:\SHARES\USERS\xxx\CheckedOutDocuments) will be also supported. If the 
    access to that directory fails the standard %TEMP% directory will be    
    used as fallback."
    I used "C:\TEMP" and now it works.......  but this cant be the solution....
    thans Ronald

  • Problems with saving edited photos using Photoshop Elements 5.0 on WIndows 8.

    Since a week I can not save the edited photos - when I try the communicate: "Caould not complete your request because of a program error" appeares. I had no problem with saving edited photos before, with the same software. My computer runs on Windows 8, 64 bit version. My Photoshop Elements is version 5.0. Where is the problem?

    W dniu 2013-06-16 15:36, dj_paige pisze:
    >
    Yes, I did it long ago.

  • PROBLEM WITH DIGITAL EDITIONS

    Hi,
    I've always encountered this problem with digital editions: Adobe Digital Editions 2.0 has encountered a problem and needs to close.  We are sorry for the inconvenience.
    I'm using Windows XP pro 2002, service pack2  on an old computer AMD Duron 901 Mhz , 384 mb RAM.
    is there a solution ?
    Thanks

    Hi
    I had the same problem, ADE 2 won't work with older AMD computers.  See http://forums.adobe.com/thread/1081859
    Older version that does work at: http://kb2.adobe.com/cps/403/kb403051/attachments/setup.exe
    good luck

  • I have a problem with external editing preferences where Photoshop will not launch when I choose "Edit In"...

    Hi. I have a problem with external editing preferences. If I add Photoshop as an external editor, it won't launch when selected, if I add it as an additional external editor it will. Why? How can I fix this as I need to use Photoshop and another program as the additional external editor.
    I use a Mac running OS X (10.8.5) and PS CS4 and LR 5.7. Any ideas on a fix? Thanks in advance.

    I don't know why Photoshop won't start. However, it's possible to create external editor presets using the additional external editor tools. There are instructions on how to do this in the Lightroom help. You could assign Photoshop and create one preset, and then assign another program and create another preset.
    I don't know if deleting your preferences would fix the problem or not. It can sometimes fix other problems.
    Preference and other file locations in Lightroom 5

  • Focus Problem with JTree and Menus

    Hi all,
    I have a problem with focus when editing a JTree and selecting a menu. The problem occurs when the user single clicks on a node, invoking the countdown to edit. If the user quickly clicks on a menu item, the focus will go to the menu item, but then when the countdown finishes, the node now has keyboard focus.
    Below is code to reproduce the problem. Click on the node, hover for a little bit, then quickly click on the menu item.
    How would I go about fixing the problem? Thanks!
    import java.awt.Container;
    import java.awt.GridLayout;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeModel;
    public class MyTree extends JTree {
         public MyTree(DefaultTreeModel treemodel) {
              setModel(treemodel);
              setRootVisible(true);
         public static void main(String[] args) {
              JFrame frame = new JFrame();
              JMenuBar bar = new JMenuBar();
              JMenu menu = new JMenu("Test");
              JMenuItem item = new JMenuItem("Item");
              menu.add(item);
              bar.add(menu);
              frame.setJMenuBar(bar);
              Container contentPane = frame.getContentPane();
              contentPane.setLayout(new GridLayout(1, 2));
              DefaultMutableTreeNode root1 = new DefaultMutableTreeNode("Root");
              root1.add(new DefaultMutableTreeNode("Root2"));
              DefaultTreeModel model = new DefaultTreeModel(root1);
              MyTree tree1 = new MyTree(model);
              tree1.setEditable(true);
              tree1.setCellEditor(
                   new ComponentTreeCellEditor(
                        tree1,
                        new ComponentTreeCellRenderer()));
              tree1.setRowHeight(0);
              contentPane.add(tree1);
              frame.pack();
              frame.show();
    import java.awt.FlowLayout;
    import java.util.EventObject;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultTreeCellEditor;
    import javax.swing.tree.DefaultTreeCellRenderer;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.TreeCellEditor;
    import javax.swing.tree.TreeCellRenderer;
    public class ComponentTreeCellEditor
         extends DefaultTreeCellEditor
         implements TreeCellEditor {
         private String m_oldValue;
         private TreeCellRenderer m_renderer = null;
         private DefaultTreeModel m_model = null;
         private JPanel m_display = null;
         private JTextField m_field = null;
         private JTree m_tree = null;
         public ComponentTreeCellEditor(
              JTree tree,
              DefaultTreeCellRenderer renderer) {
              super(tree, renderer);
              m_renderer = renderer;
              m_model = (DefaultTreeModel) tree.getModel();
              m_tree = tree;
              m_display = new JPanel(new FlowLayout(FlowLayout.LEFT));
              m_field = new JTextField();
              m_display.add(new JLabel("My Label "));
              m_display.add(m_field);
         public java.awt.Component getTreeCellEditorComponent(
              JTree tree,
              Object value,
              boolean isSelected,
              boolean expanded,
              boolean leaf,
              int row) {
              m_field.setText(value.toString());
              return m_display;
         public Object getCellEditorValue() {
              return m_field.getText();
          * The edited cell should always be selected.
          * @param anEvent the event that fired this function.
          * @return true, always.
         public boolean shouldSelectCell(EventObject anEvent) {
              return true;
          * Only edit immediately if the event is null.
          * @param event the event being studied
          * @return true if event is null, false otherwise.
         protected boolean canEditImmediately(EventObject event) {
              return (event == null);
    }

    You can provide a cell renderer to the JTree to paint the checkBox.
    The following code checks or unchecks the box with each click also:
    _tree.setCellRenderer(new DefaultTreeCellRenderer()
      private JCheckBox checkBox = null;
      public Component getTreeCellRendererComponent(JTree tree,
                                                    Object value,
                                                    boolean selected,
                                                    boolean expanded,
                                                    boolean leaf,
                                                    int row,
                                                    boolean hasFocus)
        // Each node will be drawn as a check box
        if (checkBox == null)
          checkBox  = new JCheckBox();
          checkBox .setBackground(tree.getBackground());
        DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
        checkBox.setText(node.getUserObject().toString());
        checkBox.setSelected(selected);
        return checkBox;
    });

  • Problem with JTree and memory usage

    I have problem with the JTree when memory usage is over the phisical memory( I have 512MB).
    I use JTree to display very large data about structure organization of big company. It is working fine until memory usage is over the phisical memory - then some of nodes are not visible.
    I hope somebody has an idea about this problem.

    55%, it's still 1.6Gb....there shouldn't be a problem scanning something that it says will take up 300Mb, then actually only takes up 70Mb.
    And not wrong, it obviously isn't releasing the memory when other applications need it because it doesn't, I have to close PS before it will release it. Yes, it probably is supposed to release it, but it isn't.
    Thank you for your answer (even if it did appear to me to be a bit rude/shouty, perhaps something more polite than "Wrong!" next time) but I'm sitting at my computer, and I can see what is using how much memory and when, you can't.

  • Problem with JTree converting Node to string

    I have a problem that I cannot slove with JTree. I have a DefaultMutalbeTreeNode and I need its parent and convert to string. I can get its parent OK but cannot convert it to string.
    thisnode.getParent().toString() won't work and gives an exception
    thisnode.getParent() works but how do I convert this to string to be used by a database.
    Thanks
    Peter Loo

    You are using the wrong method to convert it to a String array.
    Try replacing this line:
    String[] tabStr = (String[])strList.toArray();
    With this line:
    String[] tabStr = (String[])strList.toArray( new String[ 0 ] );
    That should work for you.

  • Problem with Jtree and a checkbox

    Hello,
    I have a problem with my tree implementation.
    I create a tree and i want to add a checkbox in each node.
    this is my code :
    DefaultMutableTreeNode root;
    root = new DefaultMutableTreeNode(new JCheckBox());
    DefaultTreeModel model = new DefaultTreeModel(root);
    _tree = new JTree(model);
    eastpane.add(tree);
    THe problem is that my checkbox doesn't appear. And a message appears
    instead of my checkbox.
    But my tree appears.
    Can anyone help me .
    Thanks

    You can provide a cell renderer to the JTree to paint the checkBox.
    The following code checks or unchecks the box with each click also:
    _tree.setCellRenderer(new DefaultTreeCellRenderer()
      private JCheckBox checkBox = null;
      public Component getTreeCellRendererComponent(JTree tree,
                                                    Object value,
                                                    boolean selected,
                                                    boolean expanded,
                                                    boolean leaf,
                                                    int row,
                                                    boolean hasFocus)
        // Each node will be drawn as a check box
        if (checkBox == null)
          checkBox  = new JCheckBox();
          checkBox .setBackground(tree.getBackground());
        DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
        checkBox.setText(node.getUserObject().toString());
        checkBox.setSelected(selected);
        return checkBox;
    });

  • Problem with Digital Editions page view

    I used Digital Editions on two books just recently and was able to fit each page of the ebook to it's full height from top to bottom.
    I just downloaded my third book to DE, and I can't seem to find the button to fit each page to their full heights (top/bottom). Instead, it's stuck on dual-page view. The single-page view button option isn't even there on the third book, but IS there on the first two books. I downloaded a fourth book and it's experiencing the same problem; stuck in dual-page view with no single-page option.
    If I try to re-size the DE window to force it into a single page view, the page numbers are all messed up appearing at random spots of each page rather than at the top right where they are suppose to be.
    I re-installed DE but the problem still persists. Is this a problem with the books in specific? Or something else?
    Thanks

    http://visguy.com/vgforum/index.php?topic=5849.15
    Paul Herber, Sandrila Ltd. Engineering and software shapes for Visio
    Sandrila Ltd

  • Problem with 'Word edit cell.vi' , Inputs transduced with the value of every row repeated

    Hello,
    Im using LV2013 with office 2013 report tool kit. I am trying to use Word edit cell to input values in table previously created in template .doc.
    Indeed, i trying the example Generate report from template and didnt works well. I search for solution and I see it was a problem with previous version but it seems not solve totally in this version for word office 2010. 
    http://digital.ni.com/public.nsf/allkb/4041ECB5D02BA57D862579A00002FE8D
    I checked this thread but i didnt get it to works. http://forums.ni.com/t5/LabVIEW/Problem-with-append-table-and-Word-2010/m-p/2190960#M702610
    Any way to solve it?.
    Thanks for help.
    Fred
    Attachments:
    error.png ‏32 KB
    Untitled 1.vi ‏19 KB
    exampleTemplate.doc ‏37 KB

    Hello, I solve it adding this to Word_insert_Table.
    http://forums.ni.com/t5/LabVIEW/Report-Generation-MS-Word-Table-Bug/td-p/1605170
    Thanks.
    Open [LabVIEW installation folder]\vi.lib\addons\_office\_wordsub.llb\Word_Insert_Table.vi
    There is a nested for loop that interprets the provided string array data and reformats it into a long ASCII string for the copy buffer. It should look like this:
    Change the nested loop to look like this:
    The changes I've made are twofold:
    1. Within the inner loop, replace the "\n" char with a Tab character
    2. Just after the inner loop, add a new "concatenate strings" function that adds "\n".

  • Problems with JTree

    Hi,
         I have a few problems while working with JTree. Here is the detail:
    I get the name of the required file from JFileChooser and add it to the root node of JTree using
    root.add(new DefaultMutableTreeNode(fileName));
    The following happens.
    1) If I add it to root, it is not added(or shown,at least) there.
    2) if I add it to a child of root, then if the node is collapsed before the event, after the event when it is expanded fileName is there.
    3) However if it is expanded before adding the fileName,the fileName is not added (or not shown).
    4) Further if I add another file(whether the node is collapsed or expanded) it is also not shown, means that it works only once during the life-time of the application.
    5) I have used JFrame and call repaint() for both the JFrame and JTree but the problem is still there.
         Please help me in solving this problem.
    Thanks in advance,
    Hamid Mukhtar,
    [email protected]
    H@isoft Technologies.

    Try doing this...
    tree.getModel().reload(node)
    node here is the node to which a new node is added

  • Problems with guided edit mode in PSE 13

    I'm having problems with some of the guided modes in PSE 13.
    The simple method for changing the  the depth of field does put a blur on my photos but the add focus area doesn't work- leaving my photos a blurry mess. The custom mode using the quick selection tool works fine.
    The zoom burst behaves in a similar fashion - it gives a zoom burst to the whole photo  but trying to  add focus doesn't work.  I've seen a few other people commenting about this in various forums but haven't seen anyone post a solution.

    murieston a écrit:
    I'm having problems with some of the guided modes in PSE 13.
    The simple method for changing the  the depth of field does put a blur on my photos but the add focus area doesn't work- leaving my photos a blurry mess. The custom mode using the quick selection tool works fine.
    The zoom burst behaves in a similar fashion - it gives a zoom burst to the whole photo  but trying to  add focus doesn't work.  I've seen a few other people commenting about this in various forums but haven't seen anyone post a solution.
    Both effects are based on the same principle: you have a blurred layer copy over the original. The step you are missing is how to use the gradient tool to show or mask the blurred layer. To better understand, switch to 'expert' view and look at your layers panel and especially at the mask in the blurred layer. You'll see that it's much easier and more flexible to do the steps in expert mode.
    - 1 - duplicate the layer
    - 2 - apply the effect (blur or zoom burst)
    - 3 - add a mask to the blurred layer
    - 4 - select the mask (Alt click in the mask icon, this makes the blank mask visible in the display area)
    - 5 - use the gradient tool (or any other painting tool) to show/reveal what should be blurred or not.
    Your problem may be due to the use of the gradient tool. Be sure the default background/colors are set to default (Click D for white on black)

  • I have a problem with the connection icon

    When i connect my ipod into my computer it all the time says "do not connect" even when itunes isnt open. is there a way to change it back to the regular charging screen with the battery on it instead of the "do not dissconnect"? i have a problem with this becuase it is hard for me to know when my ipod is fully charged. thanks in advance

    If you have your iPod set to transfer your music manually, then that “do not disconnect” message will continue to be displayed on your iPod until you manually eject it.
    You can do this by clicking on the little eject icon next to the iPod listing in the source window of iTunes, or right click on it and select “eject”. There is also an iPod 'eject' icon in the lower right hand corner of iTunes. Another way would be to use the “safely remove hardware” icon in the system tray next to the clock (looks like a grey rectangle with a green arrow above it). Click on this then select your iPod. Or through Windows, select start/my computer, right click on the iPod, select eject. With a Mac, drag the iPod into the trash.
    If you have your iPod set to automatically sync with iTunes, right click on the iPod in iTunes, select options and if you have a check mark in the box marked “enable disk use”, remove it and your iPod should automatically disconnect after it’s finished transferring music.

  • A problem with publish service icon

    I have a problem with a LR plugin I'm working on.
    My plugin is a common publish service. The code is VERY similar to the flickr plugin.
    My  problem is with publish service icon. No matter what do I do, the icon  is missing (in LR). I have set the publishServiceProvider.small_icon  property to the name of my icon file. The file is present in the same  folder, as the rest of the plugin files.
    At first, I  thought that perhaps something is wrong with the image. But when I tried  to use the same icon for the flickr plugin, everything was ok. So the  image is in correct format.
    What can be the cause of my problem?
    BTW, I use LR 3.2 and 3.3, if it's important.
    (I've already started similar discussion here http://forums.adobe.com/thread/802764?tstart=0
    but I was suggested to try on this forum.)

    I've never *noticed* a problem with icon resources, not that I would have, but I have noticed the problem with other plugin files, on Mac. Its almost as if Lightroom takes a snapshot of what's there then ignores new stuff when you reload the plugin.
    e.g. ExifMeta re-writes the metadata definition module. On Windows, simply reloading the plugin incorporates the newly re-written module, whereas on Mac, Lightroom must be restarted for it to be incorporated. Perhaps these issues are related.

Maybe you are looking for

  • Overflow:auto is not working in IE

    I am not sure. is this the right place to ask but I am struggling with one issue. I.e. I have put this code inside region header <div style = "width:auto; height:auto; overflow: auto; max-height:170;"> and in region footer </div> which is working fin

  • Currency type 10,30 and 00 need to extract data from R/3 to BI

    Hi Experts, I am working ECC6.0 version with BI 7.0, I have a issue, when I extracting data from R/3 data source (0FI_AP_3) only currency type 10 comming but I need currency type 30 and 00 also.... when I check in data source abap code it was hard co

  • Strange email issue

    So I have synced two other email addresses with my BlackBerry other than the BlackBerry address itself. One of them is a gmail account. Let's say it's [email protected] Whenever I send or reply to an email on my BlackBerry that was sent to or from th

  • Xmlns presence prevents e4x access to XML data

    I have been pulling my hair out trying to simply access data within a tag from an XML object. When I remove the xmlns attribute it works, otherwise it doesn't. In the code below when I remove "xmlns=http://xyz" the List displays the data. What do I n

  • Safari 5.1.3 WebProcess crashes CONSTANTLY

    With Safari 5.1 Apple used WebKit2 which seems to be very unstable in running "Sandboxed" (With seperated processes for UI and HTML rendering). And with Safari 5.1.1,.2, they worked on that Problem (The HTML rendering Process "WebProcess" crashes ver