TreeCellRenderer rendering JPanel leafs

I am attempting to create a jTree configuration editor which holds roots nodes that contain a label describing what they are editing. When the user clicks on the expand icon on the tree node I would like a JPanel to display. While the JPanel is working properly and displaying I am having some major problems with resizing to show the entire frame on the leaf. I have tried to set the rowHeight but this also changes the root node height. Below is the example code.
(Tree Renderer)
    private class WorkerNodeTreeRenderer extends DefaultTreeCellRenderer
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
            GuntherWorker worker = null;
            DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
            if(node.getUserObject() instanceof GuntherWorker)
                worker = (GuntherWorker)node.getUserObject();
                if(leaf)
                    WorkerTreeNode panel = new WorkerTreeNode();
                    panel.setWorker(worker);
                    panel.setPreferredSize(new Dimension(400, 170));
                    panel.setSize(new Dimension(400, 70));
                    return(panel);
            else if(node.getUserObject() instanceof String)
                JLabel nameLbl = new JLabel(node.getUserObject().toString());
                nameLbl.setFont(new Font("Dialog", Font.BOLD, 14));
                return(nameLbl);
            return(null);
    }(TreeListener)
    public class WorkerTreeNodeListener implements TreeSelectionListener
        public void valueChanged(TreeSelectionEvent e)
            DefaultMutableTreeNode node = (DefaultMutableTreeNode)configTree.getLastSelectedPathComponent();
            if(node == null)
                return;
            DefaultTreeModel dtm = (DefaultTreeModel)configTree.getModel();
            configTree.expandPath(configTree.getPathForRow(configTree.getLeadSelectionRow()));
    }(Tree population Method)
    private void populateTree()
        ConfigUtil configUtil = new ConfigUtil();
        guntherConfig = configUtil.retrieveConfig();
        Vector <GuntherWorker> workers = new Vector<GuntherWorker>(guntherConfig.getWorkers());
        DefaultTreeModel dtm = (DefaultTreeModel)configTree.getModel();
        DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode)dtm.getRoot();
        Iterator <GuntherWorker> workerIter = workers.iterator();
        while(workerIter.hasNext())
            GuntherWorker worker = workerIter.next();
            DefaultMutableTreeNode myNode = new DefaultMutableTreeNode(worker.getName());
            myNode.add(new DefaultMutableTreeNode(worker));
            rootNode.add(myNode);
        dtm.setRoot(rootNode);
    }

Just for those interested the fix was that the GUI builder in Netbeans 5.0 defaults to setting the JTree fixedRowSize and this prevents resizing of custom components properly. To fix this simply specify the rowSize as 0 in the properties which will allow you to uncheck the isFixedRowSize property.

Similar Messages

  • Custom JTree TreeCellRenderer with JPanel

    I have developed a custom TreeCellRenderer which extends JPanel to allow multple icons to be displayed and changed as the context changes. The JPanel has one or two icons and a JLabel which I control based on display context. The renderer works fine with one exception. If the initial string displayed beside the icons is short (such as 4 characters) when I try to display it with a longer string the JPanel does not resize to allow displaying the entire string. I've tried several variation to get the JPanel to resize. I've exanined the code in operation and it seems as though the size of the JLabel is being change correctly and the setPreferredSize on the JPanel is changing correctly. It just wont display without truncating the longer JLabel.
    I've reviews the forum to no avail.
    The code follows. Any thoughts are appreciated
    import javax.swing.ImageIcon;
    import java.awt.Image;
    import javax.swing.JLabel;
    import javax.swing.tree.TreeCellRenderer;
    import javax.swing.JTree;
    import com.logixpartners.planlogix.insuranceobject.*;
    import com.logixpartners.planlogix.utility.RtnObject;
    import java.awt.*;
    public class PLIconLabel extends javax.swing.JPanel implements TreeCellRenderer {
    ImageIcon a,b;
    int fWidth = 0;
    int sWidth = 0;
    String text = "";
    JLabel one, two, three;
    InsObject io;
    boolean selected;
    FontMetrics fontMetrics;
    int iconHeightPad = 0;
    int fontH, fontLen, iconH = 30+iconHeightPad;
    /** Creates a new instance of PLIconLabel */
    public PLIconLabel() {
    super(null); //null indicates no layour manager
    one = new JLabel();
    one.setIconTextGap(0);
    two = new JLabel();
    two.setIconTextGap(0);
    three = new JLabel();
    three.setIconTextGap(0);
    add(one);
    add(two);
    add(three);
    public void setIconOne(ImageIcon i) {
    a = i;
    fWidth = a.getImage().getWidth(this);
    one.setBounds(0,0, fWidth, a.getImage().getHeight(this)+iconHeightPad);
    if (b != null) {
    two.setBounds(fWidth,0,sWidth,b.getImage().getHeight(this)+iconHeightPad);
    three.setBounds(fWidth+sWidth+5,0,fontLen, iconH);
    one.setIcon(a);
    repaint();
    public void removeIconOne() {
    a = null;
    fWidth = 0;
    if (b != null) {
    two.setBounds(fWidth,0,sWidth,b.getImage().getHeight(this)+4);
    three.setBounds(fWidth+sWidth+5,0, fontLen, iconH);
    one.setIcon(a);
    repaint();
    public void setIconTwo(ImageIcon i) {
    b = i;
    sWidth = b.getImage().getWidth(this);
    two.setBounds(fWidth,0,sWidth,b.getImage().getHeight(this)+iconHeightPad);
    three.setBounds(fWidth+sWidth+5,0, fontLen, iconH);
    two.setIcon(b);
    repaint();
    public void removeIconTwo() {
    b = null;
    sWidth = 0;
    two.setIcon(b);
    two.setBounds(fWidth,0,0,0);
    three.setBounds(fWidth+sWidth+5,0,fontLen, iconH);
    repaint();
    public void setPLText(String t) {
    text = t;
    three.setText(t);
    fontMetrics = three.getFontMetrics(three.getFont());
    fontLen = fontMetrics.stringWidth(t);
    fontH = fontMetrics.getHeight();
    three.setBounds(fWidth+sWidth+5,0,
    fontLen+10,
    fontH);
    repaint();
    public java.awt.Component getTreeCellRendererComponent(JTree tree,
    Object value,
    boolean sel,
    boolean expanded,
    boolean leaf,
    int row,
    boolean hasFocus) {       
    try {
    io = (InsObject)value;
    } catch (java.lang.ClassCastException e) {
    e = e;
    setPLText(io.getBestName());
    if (io.getTypeOf().equals("Ref")){
    setPLText(io.getAttribute("Name"));
    // Setup colors for node selection
    if (sel) {
    setBackground(new java.awt.Color(64,128,128));
    } else {
    setBackground(new java.awt.Color(95,167,152));
    // Change text color of node
    three.setForeground(sel ? java.awt.Color.white : java.awt.Color.black);
    // Get proper Icon for Node
    if ((io.getClass().getName()).equals("com.logixpartners.planlogix.insuranceobject.InsObjectRef")){
    setIconTwo( (ImageIcon)((RtnObject)PLIcons.getIcon((String)io.getTypeOf())).getReturnValue());
    setIconOne((ImageIcon)PLIcons.get("RefPtr") );
    } else {
    removeIconOne();
    if (!expanded && !leaf) {
    setIconTwo( (ImageIcon)((RtnObject)PLIcons.getIconX((String)io.getTypeOf())).getReturnValue());
    } else {
    setIconTwo( (ImageIcon)((RtnObject)PLIcons.getIcon((String)io.getTypeOf())).getReturnValue());
    two.setToolTipText((String)io.getTypeOf());
    selected = sel;
    Dimension dim = new Dimension(three.getWidth()+60+fWidth+sWidth+20,iconH);
    setPreferredSize(dim);
    setMinimumSize(dim );
    setMaximumSize(dim );
    setSize(dim);
    validate();
    return this;
    }// end of class

    Addition to my original post. I found a forum post noting a similar problem. The suggest fix was to set the JTree row heigth to 0 (zero) and to add a getPreferredSize in the TreeCellRenderer, which gets called when row height is zero, and explicitly set the desired size. This works but with an exception. It seems as though the getPreferredSize is only called once when it is a leaf node being rendered. This seems to be true for expand, collaspe, and select.

  • Determing which component from a custom TreeCellRenderer was clicked on

    hi,
    i've been experimenting with finding which component has been clicked on in a JTree which has a custom tree cell renderer. I've got a piece of code that appears to work, but am unsure if this is the proper way to go about doing this, and whether it might fail under some circumstances.
    any help appreciated,
    asjf
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    public class JTreeTest1 {
       public static void main(String[] arg) throws Exception {
          final JTree tree = new JTree();
          final TreeCellRenderer renderer = new MyRenderer();
          tree.setCellRenderer(renderer);
          tree.addMouseListener(new MouseAdapter() {
             public void mouseClicked(MouseEvent e) {
                int x = e.getX(), y = e.getY();
                int row = tree.getRowForLocation(x,y);
                TreePath path = tree.getPathForLocation(x,y);
                if(path!=null) {
                   Object o = path.getLastPathComponent();
                   Rectangle r = tree.getPathBounds(path);
                   // how to detect what component has been clicked on?
                   // simplification: pretend all boolean state has no effect on renderer (which is true for the renderer below)
                   Component renderedComponent = renderer.getTreeCellRendererComponent(tree, o, false, false, false, row, false);
                   renderedComponent.setBounds(r);
                   int _x = (int) ((double)e.getX() - r.getX());
                   int _y = (int) ((double)e.getY() - r.getY());
                   Component clickedUpon = SwingUtilities.getDeepestComponentAt(renderedComponent, _x, _y);
                   if(clickedUpon instanceof JLabel) {
                      JLabel jl = (JLabel) clickedUpon;
                      System.out.println(jl.getText());
          JFrame frame = new JFrame("JTreeTest1");
          frame.getContentPane().add(tree);
          frame.pack();
          frame.setVisible(true);
    class MyRenderer extends JPanel implements TreeCellRenderer {
       JLabel custom;
       public MyRenderer() {
          super(); // flow layout
          add(new JLabel("Hello"));
          add(custom = new JLabel());
          custom.setOpaque(true);
          custom.setBackground(UIManager.getColor("Tree.background"));
          custom.setForeground(UIManager.getColor("Tree.foreground"));
          add(new JLabel("World"));
       public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isSelected, boolean expanded,
                                                     boolean leaf, int row, boolean hasFocus)
          custom.setText("("+value.toString()+")");
          return this;
    }

    My only advice would be to remember that rendered components are not actually added to the tree, so they are not a child of the tree... they actually cannot be clicked on. The rendered components are quickly used just to paint and specific image and then discarded (which is why you don't typically want to create new ones each time). When you click on the tree, there is no "rendered component" there, just an image that was painted.
    Hope this helps
    Josh Castagno
    http://www.jdc-software.com

  • Need help for JTextPane as JTree node renderer and styling in JTextPane!!!

    hello,
    I have a tree which is loading from database. And in renderer i am using JTextPane. I am putting huge text around 500 words in each node. And this Text is formatting using StyledDocument in JTextPane.
    My problem is tree is taking very long time for loading because of this styleddocument. and also size and space of nodes are not proper. how can i solve this issue.
    here is my renderer code.
    public class TraditionalViewTreeRenderer  implements  TreeCellRenderer
            private JPanel jpRubricName;
            private JTextPane lblRubricName;
            private DefaultTreeCellRenderer defaultRenderer = new DefaultTreeCellRenderer();
            private Color backgroundSelectionColor;
            private Color backgroundNonSelectionColor;
            private FontMetrics fontMetrics;
            public TraditionalViewTreeRenderer(){
                jpRubricName=new JPanel();
                lblRubricName = new JTextPane();
                jpRubricName.add(lblRubricName);
                backgroundSelectionColor    = defaultRenderer.getBackgroundSelectionColor();
                backgroundNonSelectionColor = defaultRenderer.getBackgroundNonSelectionColor();
            @Override
            public Component getTreeCellRendererComponent(JTree tree, Object value,boolean selected,boolean expanded, boolean leaf, int row,boolean hasFocus){
                Component returnVal=null;
                if(value!=null && value instanceof DefaultMutableTreeNode){  
                    Object userObj = ((DefaultMutableTreeNode)value).getUserObject();
                    if(userObj instanceof RubricNode){
                        try {
                            RubricNode node = (RubricNode) userObj;
                            if(node!=null && !node.getRubricName().equalsIgnoreCase("")){
                                if(node.getRemedyList()!=null){
                                    lblRubricName.setText("");
                                    highlightContent(lblRubricName,node.getRemedyList(),node);
    //                                fontMetrics = lblRubricName.getFontMetrics(lblRubricName.getFont());
    //                                int prefHit = fontMetrics.getHeight() * node.getRemedyList().toString().length();
    //                                if(prefHit!=tree.getRowHeight()){
    //                                    lblRubricName.setPreferredSize(new Dimension(Short.MAX_VALUE,prefHit   ) );
    lblRubricName.setPreferredSize(new Dimension(900,getContentHeight(node.getRemedyList().toString())   ) );
                            if (selected) {
                              jpRubricName.setBackground(backgroundSelectionColor);
                            } else {
                              jpRubricName.setBackground(backgroundNonSelectionColor);
                            lblRubricName.validate();
                            jpRubricName.validate();
                            returnVal = jpRubricName;
                            tree.expandRow(row);
                        } catch (Exception ex) {
                            Logger.getLogger(RepertoryTradView.class.getName()).log(Level.SEVERE, null, ex);
    //            if(returnVal==null){
    //                returnVal = defaultRenderer.getTreeCellRendererComponent(tree, value, leaf, expanded, leaf, row, hasFocus);
                return returnVal;
        private void highlightContent(JTextPane comp,List l,RubricNode rubric) throws BadLocationException{
            for(int i=l.size()-1;i>=0;i--){
                comp.getStyledDocument().insertString(0, "., ", ((Remedy)l.get(i)).getRemedyStyle());
                comp.getStyledDocument().insertString(0, l.get(i).toString(), ((Remedy)l.get(i)).getRemedyStyle());
            if(l.size()>0){
                comp.getStyledDocument().insertString(0,rubric.getRubricName()+":",rubric.getRubricStyle());
            }else{
                comp.getStyledDocument().insertString(0,rubric.getRubricName(),rubric.getRubricStyle());
        } Remedy List is the list of 300-500 words..
    see above .. n suggest me something.
    My problem is about the size and spacing of each tree node and insertString() of styled document which is taking huge time to load.

    Main performance issue there is comp.getStyledDocument().insertString(...) calls.
    Each time you call this your comp which listens model updates layout.
    Instead of using the same Document create a new instance of the Document (e.g. by kit.createDefaultDocument()). Pass the newly created document in the method to insert all the content and after the insert completed call comp.setDocument(newDocInstance)
    Also check this http://java-sl.com/JEditorPanePerformance.html

  • Editing JPanel of TreeNode in JTree

    Hi all,
    I am badly stuck with one issue.
    I have a Jtree, some of the node of Jtree contains panel, panels also has some components JtextField and JLabels.
    Tree is generating properly. Node containing Panel shows all the
    components (TextField and Labels).
    The only problem is I am not able to edit the Textbox of JPanel.
    Pls help me out.

    Override the getToolTipLocation(MouseEvent e) method in your JTree to display the tooltip in the desired location(directly over the tree node).
    Try this piece of code. I've used it in my application and it works!
    public Point getToolTipLocation(MouseEvent event)
    Point location = null;
         Point point = event.getPoint();
         TreePath path = getPathForLocation(point.x, point.y);
         if (path != null && isTextVisible(path) == false)
              TreeCellRenderer renderer = getCellRenderer();
              java.awt.Component c =
                   renderer.getTreeCellRendererComponent(
                   this,path.getLastPathComponent(),false,
                   false,false,0,false);
              if (c instanceof JLabel)
                   JLabel label = (JLabel)c;
                   int icon = label.getIcon() == null
                        ? 0 : label.getIcon().getIconWidth();
                   Rectangle cellBounds = getPathBounds(path);
                   location = new Point(cellBounds.x icon label.getIconTextGap(), cellBounds.y);
              return location;
    private boolean isTextVisible(TreePath path)
         Rectangle cellBounds = this.getPathBounds(path);
         Rectangle visibleRect = this.getVisibleRect();
         if ((visibleRect.width - cellBounds.x) < cellBounds.width)
              return false;
         return true;
    }

  • Using animation as icon for JTree node

    Hi,
    I am using a custom tree cell renderer. I have a label in the renderer, the label have gif Image Icon, but the problem is it is not getting animated. But when I use a JLabel with gif icon some where else it is working fine, but it is not working for tree node.
    package com.gopi.utilities.gui;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.GridBagConstraints;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultTreeCellRenderer;
    import javax.swing.tree.TreeCellRenderer;
    import com.gopi.remfilebrowser.gui.GUIUtil;
    import com.gopi.remfilebrowser.util.FileBrowserConstants;
    public class CustomTreeCellRenderer implements TreeCellRenderer
         private JPanel panel;
         private JLabel label;
         private TreeCellRenderer defaultRenderer;
         public CustomTreeCellRenderer()
              super();
              panel = GUIUtil.createGridBagPanel();
              label = new JLabel();
              label.setHorizontalAlignment(JLabel.LEFT);
              System.out.println("New");
              GridBagConstraints gc = new GridBagConstraints();
              GUIUtil.fillComponent(panel,label);
              defaultRenderer = new DefaultTreeCellRenderer();
         public Component getTreeCellRendererComponent(JTree tree, Object value,
                     boolean sel,
                     boolean expanded,
                     boolean leaf, int row,
                     boolean hasFocus)
              if(value instanceof NewAbstractTreeNode)
                   NewAbstractTreeNode node = (NewAbstractTreeNode) value;
                   System.out.println("dr");
                   label.setText(value.toString());
                   label.setIcon(ImageLoader.getInstance().getIcon(node.getIconKey()));
                   if(hasFocus && sel)
                        panel.setBackground(FileBrowserConstants.TREE_NODE_SELECTED_COLOR);
                   else if(sel)
                        panel.setBackground(FileBrowserConstants.TREE_NODE_UNSELECTED_COLOR);
                   else
                        panel.setBackground(Color.white);
                   return panel;
              return defaultRenderer.getTreeCellRendererComponent(tree,value,sel,expanded,leaf,row,hasFocus);
    }

    JLabels using ImageIcons are designed to display the icon as is, including animation and all.
    A CellRenderer only paints the Icon once, when the cell is painted. Much ike a rubber stamp of the JComponent. Hence, its not designed to do the animation and all.
    If you really want it, you can probably use MediaTracker and a Timer to do your animation scheduling. Might not be very pretty code though
    ICE

  • JTree Nimbus selection treeNode

    I made a jtree with a custom TreeCellRenderer. The leaf nodes are a jpanel with a checkbox in and JPanel. The problem now is that when you select a tree node, there is a selection color box beside the jpanel.
    Here is a sscce:
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Dimension;
    import javax.swing.JCheckBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTree;
    import javax.swing.UIManager;
    import javax.swing.UIManager.LookAndFeelInfo;
    import javax.swing.UnsupportedLookAndFeelException;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeCellRenderer;
    public class Users {
        private static JFrame frame;
        private static JPanel usersPanel;
        private JTree usersTree;
        public Users(){
            usersPanel = new JPanel();
            DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Gebruikers");
            DefaultMutableTreeNode willie = new DefaultMutableTreeNode("Willie");
            DefaultMutableTreeNode Anna = new DefaultMutableTreeNode("Anna");
            rootNode.add(willie);
            rootNode.add(Anna);
            usersTree = new JTree(rootNode);
            myTreeWithCheckBoxRenderer renderer = new myTreeWithCheckBoxRenderer();
            usersTree.setCellRenderer(renderer);
            usersTree.setRootVisible(true);
            usersTree.setEditable(false);
            usersTree.setOpaque(false);
            usersPanel.add(usersTree);
        class myTreeWithCheckBoxRenderer extends DefaultTreeCellRenderer {
            DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
            JPanel panel;
            JCheckBox checkBox;
            JLabel label;
            public myTreeWithCheckBoxRenderer() {
                checkBox = new JCheckBox();
                label = new JLabel("Gebruikers");
                panel = new JPanel(new BorderLayout());
                panel.add(checkBox, BorderLayout.WEST);
                panel.add(label, BorderLayout.EAST);
                panel.setBackground(Color.red);
            @Override
            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
                Component returnValue;
                if(!leaf){
                    renderer.setBackgroundSelectionColor(null);
                    renderer.setText("Gebruikers");
                    returnValue = renderer;
                else{
                    if(hasFocus){
                        panel.setBackground(Color.blue);
                    returnValue = panel;
                return returnValue;
        private static void createAndShowGUI(){
            new Users();
            frame = new JFrame("Tree");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setContentPane(usersPanel);
            frame.pack();
            frame.setPreferredSize(new Dimension(800, 600));
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
         public static void main (String[] args){
            try {
                for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        UIManager.setLookAndFeel(info.getClassName());
                        break;
            } catch (UnsupportedLookAndFeelException e) {
                // handle exception
            } catch (ClassNotFoundException e) {
                // handle exception
            } catch (InstantiationException e) {
                // handle exception
            } catch (IllegalAccessException e) {
                // handle exception
            javax.swing.SwingUtilities.invokeLater(new Runnable(){
                @Override
                public void run(){
                    createAndShowGUI();
    }I tried using a DefaultTreeCellRenderer and use the setBackgroundSelectionColor() method to null, but it doesn't change anything. Also setting the background of the JPanel to null doesn't make a change when you check with (if(hasFocus)). However I have the impression that nimbus is causing the problem, because if you comment the nimbus part out, you don't have the selection box anymore.
    Does anyone has an idea to solve this?
    Edited by: Kligham on 30-aug-2010 19:25

    Kligham wrote:
    Thank you very much!You're welcome.
    Kligham wrote:
    Problem solved. So since this cell background rendering is a Nimbus "feature", can I assume that the "not displaying of angled lines" also is a Nimbus "feature". Since the JTree tutorial says this should do the trick:
    usersTree.putClientProperty("JTree.lineStyle", "Angled");So I probably have to override it the same way, so I was wondering how you know what UIDefaults there are?Well, "JTree.lineStyle" is actually a client property and not a UIDefaults property. In other words, "JTree.lineStyle" is on the same logical level as "Nimbus.Overrides". Unfortunately, there is no way to determine which client properties a component or a component UI implementation supports except carefully examining its source code. javax.swing.plaf.synth.SynthTreeUI (the Nimbus TreeUI implementation) doesn't seem to support any client properties. It might be handled somewhere else, though.
    As an alternative to using "JTree.lineStyle", you could try to use a backgroundPainter that draws angle lines instead of the "do nothing" painter I suggested.
    To determine which UIDefaults properties are available for a given LaF implementation, you can iterate over the UIDefaults' entrySet (UIDefaults is a subclass of Hashtable). For Nimbus specifically, Jasper Potts already did that. See the [corresponding blog entry|http://www.jasperpotts.com/blog/2008/08/nimbus-uimanager-uidefaults/] and [Nimbus UIDefaults Properties List|http://jasperpotts.com/blogfiles/nimbusdefaults/nimbus.html]

  • Checkbox with JTree

    hai,
    i added checkbox to each tree node and my coding is
    import java.awt.BasicStroke;
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.ComponentOrientation;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.GridLayout;
    import java.awt.Insets;
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.RenderingHints;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.FocusEvent;
    import java.awt.event.FocusListener;
    import java.awt.event.InputEvent;
    import java.awt.event.KeyEvent;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import java.util.Arrays;
    import java.util.HashSet;
    import java.util.Iterator;
    import java.util.Set;
    import javax.swing.AbstractAction;
    import javax.swing.AbstractButton;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTree;
    import javax.swing.KeyStroke;
    import javax.swing.SwingUtilities;
    import javax.swing.UIManager;
    import javax.swing.UnsupportedLookAndFeelException;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeCellRenderer;
    import javax.swing.tree.TreeCellRenderer;
    import javax.swing.tree.TreePath;
    /** Provides checkbox-based selection of tree nodes. Override the protected
    * methods to adapt this renderer's behavior to your local tree table flavor.
    * No change listener notifications are provided.
    public class CheckBoxTreeCellRenderer implements TreeCellRenderer {
    public static final int UNSELECTABLE = 0;
    public static final int FULLSELECTED = 1;
    public static final int NOTSELECTED = 2;
    public static final int PARTIALSELECTED = 3;
    private TreeCellRenderer renderer;
    public static JCheckBox checkBox;
    private Point mouseLocation;
    private int mouseRow = -1;
    private int pressedRow = -1;
    private boolean mouseInCheck;
    private int state = NOTSELECTED;
    private Set checkedPaths;
    private JTree tree;
    private MouseHandler handler;
    /** Create a per-tree instance of the checkbox renderer. */
    public CheckBoxTreeCellRenderer(JTree tree, TreeCellRenderer original) {
    this.tree = tree;
    this.renderer = original;
    checkedPaths = new HashSet();
    checkBox = new JCheckBox();
    checkBox.setOpaque(false);
    System.out.println(checkBox.isSelected());
    checkBox.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
              trace(checkBox);
    // ActionListener actionListener = new ActionListener() {
    // public void actionPerformed(ActionEvent actionEvent) {
    // AbstractButton abstractButton = (AbstractButton) actionEvent.getSource();
    // boolean selected = abstractButton.getModel().isSelected();
    // System.out.println(selected);
    // // abstractButton.setText(newLabel);
    // checkBox.addActionListener(new ActionListener(){
    //               public void actionPerformed(ActionEvent actionEvent) {
    //                    Checkbox cb = actionEvent.getSource();
    //     boolean selected = abstractButton.getModel().isSelected();
    //     System.out.println(selected);
    checkBox.setSize(checkBox.getPreferredSize());
    private static void trace(JCheckBox cb) {
         if (cb.isSelected())
              System.out.println(cb.getText()+" is " + cb.isSelected());
         else
              System.out.println(cb.getText()+" is " + cb.isSelected());
    protected void installMouseHandler() {
    if (handler == null) {
    handler = new MouseHandler();
    addMouseHandler(handler);
    protected void addMouseHandler(MouseHandler handler) {
    tree.addMouseListener(handler);
    tree.addMouseMotionListener(handler);
    private void updateMouseLocation(Point newLoc) {
    if (mouseRow != -1) {
    repaint(mouseRow);
    mouseLocation = newLoc;
    if (mouseLocation != null) {
    mouseRow = getRow(newLoc);
    repaint(mouseRow);
    else {
    mouseRow = -1;
    if (mouseRow != -1 && mouseLocation != null) {
    Point mouseLoc = new Point(mouseLocation);
    Rectangle r = getRowBounds(mouseRow);
    if (r != null)
    mouseLoc.x -= r.x;
    mouseInCheck = isInCheckBox(mouseLoc);
    else {
    mouseInCheck = false;
    protected int getRow(Point p) {
    return tree.getRowForLocation(p.x, p.y);
    protected Rectangle getRowBounds(int row) {
    return tree.getRowBounds(row);
    protected TreePath getPathForRow(int row) {
    return tree.getPathForRow(row);
    protected int getRowForPath(TreePath path) {
    return tree.getRowForPath(path);
    public void repaint(Rectangle r) {
    tree.repaint(r);
    public void repaint() {
    tree.repaint();
    private void repaint(int row) {
    Rectangle r = getRowBounds(row);
    if (r != null)
    repaint(r);
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    installMouseHandler();
    TreePath path = getPathForRow(row);
    state = UNSELECTABLE;
    if (path != null) {
    if (isChecked(path)) {
    state = FULLSELECTED;
    else if (isPartiallyChecked(path)) {
    state = PARTIALSELECTED;
    else if (isSelectable(path)) {
    state = NOTSELECTED;
    checkBox.setSelected(state == FULLSELECTED);
    checkBox.getModel().setArmed(mouseRow == row && pressedRow == row && mouseInCheck);
    checkBox.getModel().setPressed(pressedRow == row && mouseInCheck);
    checkBox.getModel().setRollover(mouseRow == row && mouseInCheck);
    Component c = renderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    checkBox.setForeground(c.getForeground());
    if (c instanceof JLabel) {
    JLabel label = (JLabel)c;
    // Augment the icon to include the checkbox
    Icon customOpenIcon = new ImageIcon("browse.gif");
    label.setIcon(new CompoundIcon(label.getIcon()));
    return c;
    private boolean isInCheckBox(Point where) {
    Insets insets = tree.getInsets();
    int right = checkBox.getWidth();
    int left = 0;
    if (insets != null) {
    left += insets.left;
    right += insets.left;
    return where.x >= left && where.x < right;
    public boolean isExplicitlyChecked(TreePath path) {
    return checkedPaths.contains(path);
    /** Returns whether selecting the given path is allowed. The default
    * returns true. You should return false if the given path represents
    * a placeholder for a node that has not yet loaded, or anything else
    * that doesn't represent a normal, operable object in the tree.
    public boolean isSelectable(TreePath path) {
    return true;
    /** Returns whether the given path is currently checked. */
    public boolean isChecked(TreePath path) {
    if (isExplicitlyChecked(path)) {
    return true;
    else {
    if (path.getParentPath() != null) {
    return isChecked(path.getParentPath());
    else {
    return false;
    public boolean isPartiallyChecked(TreePath path) {
    Object node = path.getLastPathComponent();
    for (int i = 0; i < tree.getModel().getChildCount(node); i++) {
    Object child = tree.getModel().getChild(node, i);
    TreePath childPath = path.pathByAddingChild(child);
    if (isChecked(childPath) || isPartiallyChecked(childPath)) {
    return true;
    return false;
    private boolean isFullyChecked(TreePath parent) {
    Object node = parent.getLastPathComponent();
    for (int i = 0; i < tree.getModel().getChildCount(node); i++) {
    Object child = tree.getModel().getChild(node, i);
    TreePath childPath = parent.pathByAddingChild(child);
    if (!isExplicitlyChecked(childPath)) {
    return false;
    return true;
    public void toggleChecked(int row) {
    TreePath path = getPathForRow(row);
    boolean isChecked = isChecked(path);
    removeDescendants(path);
    if (!isChecked) {
    checkedPaths.add(path);
    setParent(path);
    repaint();
    private void setParent(TreePath path) {
    TreePath parent = path.getParentPath();
    if (parent != null) {
    if (isFullyChecked(parent)) {
    removeChildren(parent);
    checkedPaths.add(parent);
    } else {
    if (isChecked(parent)) {
    checkedPaths.remove(parent);
    addChildren(parent);
    checkedPaths.remove(path);
    setParent(parent);
    private void addChildren(TreePath parent) {
    Object node = parent.getLastPathComponent();
    for (int i = 0; i < tree.getModel().getChildCount(node); i++) {
    Object child = tree.getModel().getChild(node, i);
    TreePath path = parent.pathByAddingChild(child);
    checkedPaths.add(path);
    private void removeChildren(TreePath parent) {
    for (Iterator i = checkedPaths.iterator(); i.hasNext();) {
    TreePath p = (TreePath) i.next();
    if (p.getParentPath() != null && parent.equals(p.getParentPath())) {
    i.remove();
    private void removeDescendants(TreePath ancestor) {
    for (Iterator i = checkedPaths.iterator(); i.hasNext();) {
    TreePath path = (TreePath) i.next();
    if (ancestor.isDescendant(path)) {
    i.remove();
    /** Returns all checked rows. */
    public int[] getCheckedRows() {
    TreePath[] paths = getCheckedPaths();
    int[] rows = new int[checkedPaths.size()];
    for (int i = 0; i < checkedPaths.size(); i++) {
    rows[i] = getRowForPath(paths);
    Arrays.sort(rows);
    return rows;
    /** Returns all checked paths. */
    public TreePath[] getCheckedPaths() {
    return (TreePath[]) checkedPaths.toArray(new TreePath[checkedPaths.size()]);
    protected class MouseHandler extends MouseAdapter implements MouseMotionListener {
    public void mouseEntered(MouseEvent e) {
    updateMouseLocation(e.getPoint());
    public void mouseExited(MouseEvent e) {
    updateMouseLocation(null);
    public void mouseMoved(MouseEvent e) {
    updateMouseLocation(e.getPoint());
    public void mouseDragged(MouseEvent e) {
    updateMouseLocation(e.getPoint());
    public void mousePressed(MouseEvent e) {
    pressedRow = e.getModifiersEx() == InputEvent.BUTTON1_DOWN_MASK
    ? getRow(e.getPoint()) : -1;
    updateMouseLocation(e.getPoint());
    public void mouseReleased(MouseEvent e) {
    if (pressedRow != -1) {
    int row = getRow(e.getPoint());
    if (row == pressedRow) {
    Point p = e.getPoint();
    Rectangle r = getRowBounds(row);
    p.x -= r.x;
    if (isInCheckBox(p)) {
    toggleChecked(row);
    pressedRow = -1;
    updateMouseLocation(e.getPoint());
    public void mouseClicked(MouseEvent e){
         if(checkBox.isSelected()){
              System.out.println(checkBox.getName());
    /** Combine a JCheckBox's checkbox with another icon. */
    private final class CompoundIcon implements Icon {
    private final Icon icon;
    private final int w;
    private final int h;
    private CompoundIcon(Icon icon) {
    if (icon == null) {
    icon = new Icon() {
    public int getIconHeight() { return 0; }
    public int getIconWidth() { return 0; }
    public void paintIcon(Component c, Graphics g, int x, int y) { }
    this.icon = icon;
    this.w = icon.getIconWidth();
    this.h = icon.getIconHeight();
    public int getIconWidth() {
    return checkBox.getPreferredSize().width + w;
    public int getIconHeight() {
    return Math.max(checkBox.getPreferredSize().height, h);
    public void paintIcon(Component c, Graphics g, int x, int y) {
    if (c.getComponentOrientation().isLeftToRight()) {
    int xoffset = checkBox.getPreferredSize().width;
    int yoffset = (getIconHeight()-icon.getIconHeight())/2;
    icon.paintIcon(c, g, x + xoffset, y + yoffset);
    if (state != UNSELECTABLE) {
    paintCheckBox(g, x, y);
    else {
    int yoffset = (getIconHeight()-icon.getIconHeight())/2;
    icon.paintIcon(c, g, x, y + yoffset);
    if (state != UNSELECTABLE) {
    paintCheckBox(g, x + icon.getIconWidth(), y);
    private void paintCheckBox(Graphics g, int x, int y) {
    int yoffset;
    boolean db = checkBox.isDoubleBuffered();
    checkBox.setDoubleBuffered(false);
    try {
    yoffset = (getIconHeight()-checkBox.getPreferredSize().height)/2;
    g = g.create(x, y+yoffset, getIconWidth(), getIconHeight());
    checkBox.paint(g);
    if (state == PARTIALSELECTED) {
    final int WIDTH = 2;
    g.setColor(UIManager.getColor("CheckBox.foreground"));
    Graphics2D g2d = (Graphics2D)g;
    g2d.setStroke(new BasicStroke(WIDTH, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int w = checkBox.getWidth();
    int h = checkBox.getHeight();
    g.drawLine(w/4+2, h/2-WIDTH/2+1, w/4+w/2-3, h/2-WIDTH/2+1);
    g.dispose();
    finally {
    checkBox.setDoubleBuffered(db);
    private static String createText(TreePath[] paths) {
    if (paths.length == 0) {
    return "Nothing checked";
    String checked = "Checked:\n";
    for (int i=0;i < paths.length;i++) {
    checked += paths[i] + "\n";
    return checked;
    public static void main(String[] args) {
    try {
    final String SWITCH = "toggle-componentOrientation";
    try {
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              } catch (ClassNotFoundException e1) {
                   e1.printStackTrace();
              } catch (InstantiationException e1) {
                   e1.printStackTrace();
              } catch (IllegalAccessException e1) {
                   e1.printStackTrace();
              } catch (UnsupportedLookAndFeelException e1) {
                   e1.printStackTrace();
    JFrame frame = new JFrame("Tree with Check Boxes");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final DefaultMutableTreeNode a = new DefaultMutableTreeNode("Node 1");
    for(int i =0 ; i<3; i++ ){
         DefaultMutableTreeNode b = new DefaultMutableTreeNode("ChildNode "+i);
         a.add(b);
    DefaultMutableTreeNode e = new DefaultMutableTreeNode("Node 2");
    for(int i =0 ; i<3; i++ ){
         DefaultMutableTreeNode f = new DefaultMutableTreeNode("ChildNode "+i);
         e.add(f);
    DefaultMutableTreeNode al = new DefaultMutableTreeNode("Sample");
    al.add(a);
    al.add(e);
    final JTree tree = new JTree(al);
    final CheckBoxTreeCellRenderer r =
    new CheckBoxTreeCellRenderer(tree, tree.getCellRenderer());
    tree.setCellRenderer(r);
    int rc = tree.getRowCount();
    tree.getActionMap().put(SWITCH, new AbstractAction(SWITCH) {
    public void actionPerformed(ActionEvent e) {
    ComponentOrientation o = tree.getComponentOrientation();
    if (o.isLeftToRight()) {
    o = ComponentOrientation.RIGHT_TO_LEFT;
    else {
    o = ComponentOrientation.LEFT_TO_RIGHT;
    tree.setComponentOrientation(o);
    tree.repaint();
    int mask = InputEvent.SHIFT_MASK|Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    tree.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_O, mask), SWITCH);
    final JTextArea text = new JTextArea(createText(r.getCheckedPaths()));
    text.setPreferredSize(new Dimension(200, 100));
    tree.addMouseListener(new MouseAdapter() {
    public void mouseReleased(MouseEvent e) {
    // Invoke later to ensure all mouse handling is completed
    SwingUtilities.invokeLater(new Runnable() { public void run() {
    text.setText(createText(r.getCheckedPaths()));
    JScrollPane pane = new JScrollPane(tree);
    frame.getContentPane().add(pane);
    // frame.getContentPane().add(new JScrollPane(text), BorderLayout.SOUTH);
    frame.pack();
    frame.setSize(600,400);
    frame.setVisible(true);
    catch(Exception e) {
    e.printStackTrace();
    System.exit(1);
    now i need to get nodes names which has been selected, how can i do this
    can anyone help me ...
    regards,
    shobi

    Also, use code tags and post a SSCCE -- I'm sure more of your posted code is irrelevant to your question and few people are going to look at a code listing that long.
    [http://mindprod.com/jgloss/sscce.html]

  • How to highlight node in JTree?

    After the tree has been displayed, I want to highlight the nodes matching some certain keywords. How to implement that? Nothing useful is found in past threads.
    thanks.

    to take a wild guess:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.tree.*;
    public class HighlightTreeNodeTest {
      private final JTree tree       = new JTree();
      private final JTextField field = new JTextField("foo");
      private final JButton button   = new JButton();
      private final MyTreeCellRenderer renderer =
        new MyTreeCellRenderer(tree.getCellRenderer());
      public JComponent makeUI() {
        field.getDocument().addDocumentListener(new DocumentListener() {
          @Override public void insertUpdate(DocumentEvent e) {
            fireDocumentChangeEvent();
          @Override public void removeUpdate(DocumentEvent e) {
            fireDocumentChangeEvent();
          @Override public void changedUpdate(DocumentEvent e) {}
        tree.setCellRenderer(renderer);
        renderer.q = field.getText();
        fireDocumentChangeEvent();
        JPanel p = new JPanel(new BorderLayout(5, 5));
        p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
        p.add(field, BorderLayout.NORTH);
        p.add(new JScrollPane(tree));
        return p;
      private void fireDocumentChangeEvent() {
        String q = field.getText();
        renderer.q = q;
        TreePath root = tree.getPathForRow(0);
        collapseAll(tree, root);
        if (!q.isEmpty()) searchTree(tree, root, q);
        tree.repaint();
      private static void searchTree(JTree tree, TreePath path, String q) {
        TreeNode node = (TreeNode)path.getLastPathComponent();
        if (node==null) return;
        if (node.toString().startsWith(q)) tree.expandPath(path.getParentPath());
        if (!node.isLeaf() && node.getChildCount()>=0) {
          Enumeration e = node.children();
          while (e.hasMoreElements())
            searchTree(tree, path.pathByAddingChild(e.nextElement()), q);
      private static void collapseAll(JTree tree, TreePath parent) {
        TreeNode node = (TreeNode)parent.getLastPathComponent();
        if (!node.isLeaf() && node.getChildCount()>=0) {
          Enumeration e = node.children();
          while (e.hasMoreElements()) {
            TreeNode n = (TreeNode)e.nextElement();
            TreePath path = parent.pathByAddingChild(n);
            collapseAll(tree, path);
        tree.collapsePath(parent);
      public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
          @Override public void run() { createAndShowGUI(); }
      public static void createAndShowGUI() {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        f.getContentPane().add(new HighlightTreeNodeTest().makeUI());
        f.setSize(320, 240);
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    class MyTreeCellRenderer extends DefaultTreeCellRenderer {
      private final TreeCellRenderer renderer;
      public String q;
      public MyTreeCellRenderer(TreeCellRenderer renderer) {
        this.renderer = renderer;
      @Override public Component getTreeCellRendererComponent(
          JTree tree, Object value, boolean isSelected, boolean expanded,
          boolean leaf, int row, boolean hasFocus) {
        JComponent c = (JComponent)renderer.getTreeCellRendererComponent(
            tree, value, isSelected, expanded, leaf, row, hasFocus);
        if (isSelected) {
          c.setOpaque(false);
          c.setForeground(getTextSelectionColor());
        } else {
          c.setOpaque(true);
          if (q!=null && !q.isEmpty() && value.toString().startsWith(q)) {
            c.setForeground(getTextNonSelectionColor());
            c.setBackground(Color.YELLOW);
          } else {
            c.setForeground(getTextNonSelectionColor());
            c.setBackground(getBackgroundNonSelectionColor());
        return c;
    }

  • Jbuttons in JTree

    Hello Guys!
    I have got a problem I have got a JTree with JButtons but only the childs are Buttons, pleas can you help me that the parents are also JButtons.
    package com.cbm.vis.util;
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import com.cbm.util.CBMIConstant;
    import com.cbm.vis.cashbook.CBM_KBEntry;
    import com.cbm.vis.cashbook.CBM_KBList;
    import com.cbm.vis.cashbook.CBM_KBSearch;
    import com.cbm.vis.cmanagment.CBM_Customerentry;
    import com.cbm.vis.cmanagment.CBM_Customerdelete;
    import com.cbm.vis.main.CBMMain;
    *  Name:    JTree mit Buttons                            *
    *  Author:  Thomas Rockenschaub                          *
    *  Date:    30.12.2006                                *
    *  Modified Date: 5.1.2007                                   *     
    *  Version: 1.8 [Beta]                                *
    *  Description: Tree um auf die diversen Funktion     *
    *                      des Programms zugreifen zu k�nnen     *
    public class CBMJTree
    implements CBMIConstant
         /* Konstante f�r die Gr��e des JTrees im Hauptfenster */
         private static final int m_sizex = 200;
         private CBM Kassabuch[] = {
                new CBM("  KB Eintrag     "),
                new CBM("  KB Editieren  "),
                new CBM("  KB L�schen  "),
                new CBM("  KB Auflisten  "),
                new CBM("  KB Drucken   ") };
         private CBM Kundenverwaltung[] = {
                 new CBM("  Kundeneintrag      "),
                 new CBM("  Kunden Editieren  "),
                 new CBM("  Kunden L�schen  "),
                 new CBM("  Kunden Auflisten  "),
                 new CBM("  Kunden Drucken   ") };
         private CBM Administrator[] = {
                 new CBM("  AD Einstellungen "),
                 new CBM("  AD Benutzer          "),
                 new CBM("  AD Login/Logout   "),
                 new CBM("  AD Informationen ")};
         private Vector KBVector;
         private Vector KVVector;
         private Vector ADVector;
         private Vector rootVector;
         private JTree tree;
         private JScrollPane scroll;
       public CBMJTree()
           KBVector = new NameVector("Kassabuch", Kassabuch);
           KVVector = new NameVector("Kundenverwaltung", Kundenverwaltung);
           ADVector = new NameVector("Administrator", Administrator);
           Object rootNodes[] = { KBVector, KVVector, ADVector };
           rootVector = new NameVector("Root", rootNodes);
           tree = new JTree(rootVector);
           TreeCellRenderer renderer = new CBMCellRenderer();
           tree.setCellRenderer(renderer);
           scroll = new JScrollPane(tree);
           scroll.setMinimumSize(new Dimension(m_sizex,m_fgry));
       public Component getJScrollPane()
            return scroll;
    class CBM
         String title;
         public CBM(String title)
           this.title = title;
         public String getTitle()
           return title;
    class CBMCellRenderer
    implements TreeCellRenderer
          private JLabel titleLabel;
         private boolean choose=true;
         private int value1, value2;
         private JPanel renderer;
         private DefaultTreeCellRenderer defaultRenderer = new DefaultTreeCellRenderer();
         private Color backgroundSelectionColor;
         private Color backgroundNonSelectionColor;
         private JButton button;
         public CBMCellRenderer()
             renderer = new JPanel(new FlowLayout(FlowLayout.RIGHT,6,6));
            titleLabel = new JLabel(" ");
            titleLabel.setForeground(Color.blue);
            button=new JButton();
            renderer.add(button);
            backgroundSelectionColor = defaultRenderer.getBackgroundSelectionColor();
            backgroundNonSelectionColor = defaultRenderer.getBackgroundNonSelectionColor();
         public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
            Component returnValue = null;
            if ((value != null) && (value instanceof DefaultMutableTreeNode))
               Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
               if (userObject instanceof CBM)
                  CBM book = (CBM) userObject;
                  button.setText(book.getTitle());
                  if (selected)
                      renderer.setBackground(backgroundSelectionColor);
                     String react = book.getTitle();
                      if(choose==false)
                           if(react.equals("  KB Eintrag     "))
                                value2=1;
                           else if(react.equals("  KB Editieren  "))
                                value2=2;
                           else if(react.equals("  KB L�schen  "))
                                value2=3;
                           else if(react.equals("  KB Drucken   "))
                                 value2=4;
                           else if(react.equals("  KB Auflisten  "))
                                      value2=5;
                           else if(react.equals("  Kundeneintrag      "))
                                value2=6;
                           else if(react.equals("  Kunden Editieren  "))
                                value2=7;
                           else if(react.equals("  Kunden L�schen  "))
                                value2=8;
                           else if(react.equals("  Kunden Drucken   "))
                                 value2=9;
                           else if(react.equals("  Kunden Auflisten  "))
                                      value2=10;
                           else if(react.equals("  AD Einstellungen "))
                                value2=11;
                           else if(react.equals("  AD Benutzer          "))
                                value2=12;
                           else if(react.equals("  AD Login/Logout   "))
                                value2=13;
                           else if(react.equals("  AD Informationen "))
                                 value2=14;
                           if(value1!=value2)
                               choose=true;
                     //Hier kann jetzt auf die Buttons reagiert werden
                     if(choose==true)
                          if(react.equals("  Kundeneintrag      "))
                               System.out.println(""+react);
                               CBM_Customerentry Custentry=new CBM_Customerentry();
                               CBMMain.setrightPanelComponent2(Custentry.getMainJPanel());
                               CBMMain.setrightPanelComponent3(Custentry.getJButtonPanel());
                               value1=6;
                               choose=false;
                          }else if(react.equals("  Kunden Editieren  "))
                               System.out.println(""+react);
                               value1=7;
                               choose=false;
                          }else if(react.equals("  Kunden L�schen  "))
                               System.out.println(""+react);
                               /*CBM_Customerdelete Custdelete=new CBM_Customerdelete();
                               CBMMain.setrightPanelComponent2(Custdelete.getMainJPanel());
                               CBMMain.setrightPanelComponent3(Custdelete.getJButtonPanel());*/
                               value1=8;
                               choose=false;
                          }else if(react.equals("  Kunden Auflisten  "))
                               System.out.println(""+react);
                               value1=10;
                               choose=false;
                          }else if(react.equals("  Kunden Drucken   "))
                               System.out.println(""+react);
                               value1=9;
                               choose=false;
                          }else if(react.equals("  KB Eintrag     "))
                               System.out.println(""+react);
                               CBM_KBEntry entry=new CBM_KBEntry();
                               CBMMain.setrightPanelComponent2(entry.getMainJPanel());
                               CBMMain.setrightPanelComponent3(entry.getJButtonPanel());
                               value1=1;
                               choose=false;
                          }else if(react.equals("  KB Editieren  "))
                               System.out.println(""+react);
                               CBM_KBSearch entry=new CBM_KBSearch();
                               CBMMain.setrightPanelComponent2(entry.getMainJPanel());
                               CBMMain.setrightPanelComponent3(entry.getJButtonPanel());
                               value1=2;
                               choose=false;
                          }else if(react.equals("  KB L�schen  "))
                               CBM_KBSearch entry=new CBM_KBSearch();
                               CBMMain.setrightPanelComponent2(entry.getMainJPanel());
                               CBMMain.setrightPanelComponent3(entry.getJButtonPanel());
                               System.out.println(""+react);
                               value1=3;
                               choose=false;
                          }else if(react.equals("  KB Auflisten  "))
                               CBM_KBList entry=new CBM_KBList();
                               CBMMain.setrightPanelComponent2(entry.getMainJPanel());
                               //CBMMain.setrightPanelComponent3(entry.getJButtonPanel());
                               System.out.println(""+react);
                               value1=5;
                               choose=false;
                          }else if(react.equals("  KB Drucken   "))
                               System.out.println(""+react);
                               value1=4;
                               choose=false;
                          }else if(react.equals("  AD Einstellungen "))
                               System.out.println(""+react);
                               value1=11;
                               choose=false;
                          }else if(react.equals("  AD Benutzer            "))
                               System.out.println(""+react);
                               value1=12;
                               choose=false;
                          }else if(react.equals("  AD Login/Logout   "))
                               System.out.println(""+react);
                               value1=13;
                               choose=false;
                          }else if(react.equals("  AD Informationen "))
                               System.out.println(""+react);
                               value1=14;
                               choose=false;
                  else
                     renderer.setBackground(backgroundNonSelectionColor);
                  renderer.setEnabled(tree.isEnabled());
                  returnValue = renderer;
            if (returnValue == null)
               returnValue = defaultRenderer.getTreeCellRendererComponent(tree,value, selected, expanded, leaf, row, hasFocus);
            return returnValue;
    class NameVector
    extends Vector
         private static final long serialVersionUID = 1L;
         String name;
         public NameVector(String name)
           this.name = name;
         public NameVector(String name, Object elements[])
            this.name = name;
            for (int i = 0, n = elements.length; i < n; i++)
               add(elements);
    public String toString()
    return "[" + name + "]";

    To post code, use the code tags -- [code]Your Code[/code]will display asYour CodeOr use the code button above the editing area and paste your code between the tags it generates.
    db

  • DefaultTreeModel.removeNodeFromParent throwing NullPointerException

    I have an applet which involves editing data represented by a JTree. However, I'm getting this exception when I try to remove a node from the tree (to move it by subsequently inserting it at +/-1 position):
    java.lang.NullPointerException
    at javax.swing.plaf.basic.BasicTreeUI.completeEditing(Unknown Source)
    at javax.swing.plaf.basic.BasicTreeUI.completeEditing(Unknown Source)
    at javax.swing.plaf.basic.BasicTreeUI$TreeSelectionHandler.valueChanged(Unknown Source)
    at javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(Unknown Source)
    at javax.swing.tree.DefaultTreeSelectionModel.notifyPathChange(Unknown Source)
    at javax.swing.tree.DefaultTreeSelectionModel.removeSelectionPaths(Unknown Source)
    at javax.swing.JTree.removeDescendantSelectedPaths(Unknown Source)
    at javax.swing.JTree.removeDescendantSelectedPaths(Unknown Source)
    at javax.swing.JTree$TreeModelHandler.treeNodesRemoved(Unknown Source)
    at javax.swing.tree.DefaultTreeModel.fireTreeNodesRemoved(Unknown Source)
    at javax.swing.tree.DefaultTreeModel.nodesWereRemoved(Unknown Source)
    at javax.swing.tree.DefaultTreeModel.removeNodeFromParent(Unknown Source)
    at ...[my code from here]This is the code that moves the node:
    DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)myTree.getLastSelectedPathComponent();
    factbookTree.setEnabled(false);
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode)selectedNode.getParent();
    DefaultTreeModel treeModel = (DefaultTreeModel)factbookTree.getModel();
    int oldIndex = treeModel.getIndexOfChild(parent,selectedNode);
    int newIndex = oldIndex + move;
    //throws exception here:
    treeModel.removeNodeFromParent(selectedNode);
    //This also causes exception:
    //parent.remove(selectedNode);
    //treeModel.nodesWereRemoved(parent, new int[] {oldIndex}, new Object[] {selectedNode});Any ideas as to what the problem is?
    It started throwing this error when I changed my objects overriding JTree and TreeNode, but I'm not doing anything far out here, just getting the CellRenderer to include a JCheckBox and adding code to store the state of the JCheckBox. There is no multithreading that I'm adding. The node is being visibly removed from the applet before the exception. My only thought was that I needed to initialise the tree model somwhere myself - the tree is being constructed by passing it the root node.
    I'm using JDK 1.4.1 as a JApplet with the Java Plug-In on W2K.
    cheers,
    Andy

    Yeah, I checked that it wasn't null. I've hacked the code down and here's a complete listing which shows the problem, apologies for dodgy formatting. The code is modified from the JCheckTree implementation I found at http://www.fawcette.com/archives/premier/mgznarch/javapro/2001/01jan01/vc0101/vc0101.asp
    // FactbookBrowser.java
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    public class FactbookBrowser extends JApplet implements ActionListener {
         JButton upButton;
         JButton downButton;
         JCheckTree factbookTree;
         public FactbookBrowser() {
              //Set up the tree display
              CheckTreeNode root = new CheckTreeNode("Root");
              CheckTreeNode one = new CheckTreeNode("one");
              CheckTreeNode two = new CheckTreeNode("two");
              CheckTreeNode three = new CheckTreeNode("three");
              root.add(one);
              root.add(two);
              root.add(three);
              factbookTree = new JCheckTree(root);
              factbookTree.getSelectionModel().setSelectionMode(
                   TreeSelectionModel.SINGLE_TREE_SELECTION
              factbookTree.putClientProperty("JTree.lineStyle", "Angled");
              JPanel moveButtons = new JPanel();
              upButton = new JButton("up");
              downButton = new JButton("down");
              moveButtons.add(upButton);
              moveButtons.add(downButton);
              upButton.addActionListener(this);
              downButton.addActionListener(this);
              //Add everything to scrollpanes, split panes and this
              JScrollPane treeScroll = new JScrollPane(factbookTree);
              JPanel treePanel = new JPanel();
              treePanel.setLayout(new BorderLayout());
              treePanel.add(treeScroll, BorderLayout.CENTER);
              treePanel.add(moveButtons, BorderLayout.SOUTH);
              this.getContentPane().setLayout(new BorderLayout());
              this.getContentPane().add(treePanel, BorderLayout.CENTER);
         private void moveNode(int move) {
              DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)factbookTree.getLastSelectedPathComponent();
            if ((move == -1) && (selectedNode.getPreviousSibling() == null)) {
                   System.out.println("Node already at start of section, can't move up");
                   return;
              } else if ((move == 1) && (selectedNode.getNextSibling() == null)) {
                   System.out.println("Node already at end of section, can't move down");
                   return;
              } else if ((move != 1) && (move != -1)) {
                   System.out.println("Can't move node more than one place");
                   return;
              DefaultMutableTreeNode parent = (DefaultMutableTreeNode)selectedNode.getParent();
              DefaultTreeModel treeModel = (DefaultTreeModel)factbookTree.getModel();
              int oldIndex = treeModel.getIndexOfChild(parent,selectedNode);
              int newIndex = oldIndex + move;
    System.out.println("*** treeModel:"+treeModel+" selectedNode:"+selectedNode+" new index:"+newIndex);
    //@todo Throwing exception here! WHY?
              treeModel.removeNodeFromParent(selectedNode);
              //parent.remove(selectedNode);
              //treeModel.nodesWereRemoved(parent, new int[] {oldIndex}, new Object[] {selectedNode});
    System.out.println("*** Removed node, inserting");
              treeModel.insertNodeInto(selectedNode,parent,newIndex);
    System.out.println("*** Inserted Node");
              TreePath newPath = new TreePath(selectedNode.getPath());
              factbookTree.scrollPathToVisible(newPath);
              factbookTree.setSelectionPath(newPath);
              factbookTree.repaint();
         public void actionPerformed(ActionEvent ae) {
              if (ae.getSource() == upButton) {
                   //Move the currently selected node up within its folder
                   moveNode(-1);
              } else if (ae.getSource() == downButton) {
                   //Move the currently selected node up within its folder
                   moveNode(1);
        public static void main(String[] args) {
            FactbookBrowser browser = new FactbookBrowser();
    // JCheckTree.java
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    public class JCheckTree extends JTree {
      public JCheckTree(TreeNode root) {
        super(root);
        super.setCellRenderer(new CheckTreeCellRenderer(this));
        setCellEditor(new CheckTreeCellEditor(this));
        setEditable(true);
      public void setCellRenderer(TreeCellRenderer renderer) {
        super.setCellRenderer(new CheckTreeCellRenderer(this, renderer));
      public void setEditorRenderer(TreeCellRenderer renderer) {
        setCellEditor(new CheckTreeCellEditor(this, renderer));
    // CheckTreeNode.java
    import java.util.*;
    import javax.swing.tree.*;
    public class CheckTreeNode extends DefaultMutableTreeNode {
         protected boolean selected, propagate;
         public CheckTreeNode(Object data) {
              this(data, false, true);
         public CheckTreeNode(Object data, boolean selected) {
              this(data, selected, true);
         public CheckTreeNode(Object data, boolean selected, boolean propagate) {
              super(data);
              this.selected = selected;
              this.propagate = propagate;
         public boolean isSelected() {
              return selected;
         public void setSelected(boolean selected) {
              this.selected = selected;
              if (propagate)
              propagateSelected(selected);
         public void propagateSelected(boolean selected) {
              Enumeration enum = children();
              while (enum.hasMoreElements()) {
                   CheckTreeNode node = (CheckTreeNode)enum.nextElement();
                   node.setSelected(selected);
         public void setUserObject(Object obj) {
              if (obj == this) return;
              super.setUserObject(obj);
    // CheckTreeCellRenderer.java
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    public class CheckTreeCellRenderer extends JPanel implements TreeCellRenderer {
         protected CheckTreeNode node;
         protected TreeCellRenderer renderer;
         protected JCheckBox check;
         public CheckTreeCellRenderer(JTree tree) {
              this(tree, new DefaultTreeCellRenderer());
         public CheckTreeCellRenderer(JTree tree, TreeCellRenderer renderer) {
              setLayout(new BorderLayout());
              this.renderer = renderer;
              add(BorderLayout.CENTER,
              renderer.getTreeCellRendererComponent(tree, "", true, true, true, 0, true));
              check = new JCheckBox();
              add(BorderLayout.WEST, check);
         public Component getTreeCellRendererComponent(JTree tree,
                                  Object value,
                                  boolean selected,
                                  boolean expanded,
                                  boolean leaf,
                                  int row,
                                  boolean hasFocus) {
              if (value instanceof CheckTreeNode) {
                   node = (CheckTreeNode)value;
                   check.setSelected(node.isSelected());
                   value = node.getUserObject();
              renderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
              return this;
    // CheckTreeCellEditor.java
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    public class CheckTreeCellEditor extends CheckTreeCellRenderer implements TreeCellEditor, ActionListener {
      protected CellEditorListener list;
      public CheckTreeCellEditor(JTree tree)
        this(tree, new DefaultTreeCellRenderer());
      public CheckTreeCellEditor(JTree tree, TreeCellRenderer renderer)
        super(tree, renderer);
        check.addActionListener(this);
      public Component getTreeCellEditorComponent(
        JTree tree, Object value, boolean selected,
        boolean expanded, boolean leaf, int row)
        return getTreeCellRendererComponent(
          tree, value, true, expanded, leaf, row, true);
      public boolean stopCellEditing()
        return true;
      public Object getCellEditorValue()
        node.setSelected(check.isSelected());
        return node;
      public boolean isCellEditable(EventObject event)
        return true;
      public boolean shouldSelectCell(EventObject event)
        return true;
      public void  cancelCellEditing()
        fireEditingCanceled();
         HashSet listeners = new HashSet();
      public void addCellEditorListener(CellEditorListener listener) {
        listeners.add(listener);
      public void removeCellEditorListener(CellEditorListener listener) {
        listeners.remove(listener);
      protected void fireEditingStopped() {
         Iterator i = listeners.iterator();
         while (i.hasNext()) {
              ((CellEditorListener)i.next()).editingStopped(new ChangeEvent(this));
      protected void fireEditingCanceled() {
         Iterator i = listeners.iterator();
         while (i.hasNext()) {
              ((CellEditorListener)i.next()).editingCanceled(new ChangeEvent(this));
      public void actionPerformed(ActionEvent event) {
        fireEditingStopped();
    }

  • Display files also in tree?

    hai, to every one
    This program displaying folders from the local system, But my problem is, it was not displaying files.
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    public class FileTree1
      extends JFrame
      public static final ImageIcon ICON_COMPUTER =
        new ImageIcon("computer.gif");
      public static final ImageIcon ICON_DISK =
        new ImageIcon("disk.gif");
      public static final ImageIcon ICON_FOLDER =
        new ImageIcon("folder.gif");
      public static final ImageIcon ICON_EXPANDEDFOLDER =
        new ImageIcon("expandedfolder.gif");
      protected JTree  m_tree;
      protected DefaultTreeModel m_model;
      protected JTextField m_display;
      public FileTree1()
        super("Directories Tree");
        setSize(400, 300);
        DefaultMutableTreeNode top = new DefaultMutableTreeNode(
          new IconData(ICON_COMPUTER, null, "Computer"));
        DefaultMutableTreeNode node;
        File[] roots = File.listRoots();
        for (int k=0; k<roots.length; k++)
          node = new DefaultMutableTreeNode(new IconData(ICON_DISK,
            null, new FileNode(roots[k])));
          top.add(node);
                            node.add( new DefaultMutableTreeNode(new Boolean(true)));
        m_model = new DefaultTreeModel(top);
        m_tree = new JTree(m_model);
                    m_tree.putClientProperty("JTree.lineStyle", "Angled");
        TreeCellRenderer renderer = new
          IconCellRenderer();
        m_tree.setCellRenderer(renderer);
        m_tree.addTreeExpansionListener(new
          DirExpansionListener());
        m_tree.addTreeSelectionListener(new
          DirSelectionListener());
        m_tree.getSelectionModel().setSelectionMode(
          TreeSelectionModel.SINGLE_TREE_SELECTION);
        m_tree.setShowsRootHandles(true);
        m_tree.setEditable(false);
        JScrollPane s = new JScrollPane();
        s.getViewport().add(m_tree);
        getContentPane().add(s, BorderLayout.CENTER);
        m_display = new JTextField();
        m_display.setEditable(false);
        getContentPane().add(m_display, BorderLayout.NORTH);
        WindowListener wndCloser = new WindowAdapter()
          public void windowClosing(WindowEvent e)
            System.exit(0);
        addWindowListener(wndCloser);
        setVisible(true);
      DefaultMutableTreeNode getTreeNode(TreePath path)
        return (DefaultMutableTreeNode)(path.getLastPathComponent());
      FileNode getFileNode(DefaultMutableTreeNode node)
        if (node == null)
          return null;
        Object obj = node.getUserObject();
        if (obj instanceof IconData)
          obj = ((IconData)obj).getObject();
        if (obj instanceof FileNode)
          return (FileNode)obj;
        else
          return null;
        // Make sure expansion is threaded and updating the tree model
        // only occurs within the event dispatching thread.
        class DirExpansionListener implements TreeExpansionListener
            public void treeExpanded(TreeExpansionEvent event)
                final DefaultMutableTreeNode node = getTreeNode(
                    event.getPath());
                final FileNode fnode = getFileNode(node);
                Thread runner = new Thread()
                  public void run()
                    if (fnode != null && fnode.expand(node))
                      Runnable runnable = new Runnable()
                        public void run()
                           m_model.reload(node);
                      SwingUtilities.invokeLater(runnable);
                runner.start();
            public void treeCollapsed(TreeExpansionEvent event) {}
      class DirSelectionListener
        implements TreeSelectionListener
        public void valueChanged(TreeSelectionEvent event)
          DefaultMutableTreeNode node = getTreeNode(
            event.getPath());
          FileNode fnode = getFileNode(node);
          if (fnode != null)
            m_display.setText(fnode.getFile().
              getAbsolutePath());
          else
            m_display.setText("");
      public static void main(String argv[])
        new FileTree1();
    class IconCellRenderer
      extends    JLabel
      implements TreeCellRenderer
      protected Color m_textSelectionColor;
      protected Color m_textNonSelectionColor;
      protected Color m_bkSelectionColor;
      protected Color m_bkNonSelectionColor;
      protected Color m_borderSelectionColor;
      protected boolean m_selected;
      public IconCellRenderer()
        super();
        m_textSelectionColor = UIManager.getColor(
          "Tree.selectionForeground");
        m_textNonSelectionColor = UIManager.getColor(
          "Tree.textForeground");
        m_bkSelectionColor = UIManager.getColor(
          "Tree.selectionBackground");
        m_bkNonSelectionColor = UIManager.getColor(
          "Tree.textBackground");
        m_borderSelectionColor = UIManager.getColor(
          "Tree.selectionBorderColor");
        setOpaque(false);
      public Component getTreeCellRendererComponent(JTree tree,
        Object value, boolean sel, boolean expanded, boolean leaf,
        int row, boolean hasFocus)
        DefaultMutableTreeNode node =
          (DefaultMutableTreeNode)value;
        Object obj = node.getUserObject();
        setText(obj.toString());
                    if (obj instanceof Boolean)
                      setText("Retrieving data...");
        if (obj instanceof IconData)
          IconData idata = (IconData)obj;
          if (expanded)
            setIcon(idata.getExpandedIcon());
          else
            setIcon(idata.getIcon());
        else
          setIcon(null);
        setFont(tree.getFont());
        setForeground(sel ? m_textSelectionColor :
          m_textNonSelectionColor);
        setBackground(sel ? m_bkSelectionColor :
          m_bkNonSelectionColor);
        m_selected = sel;
        return this;
      public void paintComponent(Graphics g)
        Color bColor = getBackground();
        Icon icon = getIcon();
        g.setColor(bColor);
        int offset = 0;
        if(icon != null && getText() != null)
          offset = (icon.getIconWidth() + getIconTextGap());
        g.fillRect(offset, 0, getWidth() - 1 - offset,
          getHeight() - 1);
        if (m_selected)
          g.setColor(m_borderSelectionColor);
          g.drawRect(offset, 0, getWidth()-1-offset, getHeight()-1);
        super.paintComponent(g);
    class IconData
      protected Icon   m_icon;
      protected Icon   m_expandedIcon;
      protected Object m_data;
      public IconData(Icon icon, Object data)
        m_icon = icon;
        m_expandedIcon = null;
        m_data = data;
      public IconData(Icon icon, Icon expandedIcon, Object data)
        m_icon = icon;
        m_expandedIcon = expandedIcon;
        m_data = data;
      public Icon getIcon()
        return m_icon;
      public Icon getExpandedIcon()
        return m_expandedIcon!=null ? m_expandedIcon : m_icon;
      public Object getObject()
        return m_data;
      public String toString()
        return m_data.toString();
    class FileNode
      protected File m_file;
      public FileNode(File file)
        m_file = file;
      public File getFile()
        return m_file;
      public String toString()
        return m_file.getName().length() > 0 ? m_file.getName() :
          m_file.getPath();
      public boolean expand(DefaultMutableTreeNode parent)
        DefaultMutableTreeNode flag =
          (DefaultMutableTreeNode)parent.getFirstChild();
        if (flag==null)    // No flag
          return false;
        Object obj = flag.getUserObject();
        if (!(obj instanceof Boolean))
          return false;      // Already expanded
        parent.removeAllChildren();  // Remove Flag
        File[] files = listFiles();
        if (files == null)
          return true;
        Vector v = new Vector();
        for (int k=0; k<files.length; k++)
                   /*File child = new File(dir, list);
              String name = (child.getName()) ;
              if(child.isDirectory()) add(new Node(child));
              else add(new Node(child));*/
    File f = files[k];
    if (!(f.isDirectory()))
    continue;
    FileNode newNode = new FileNode(f);
    boolean isAdded = false;
    for (int i=0; i<v.size(); i++)
    FileNode nd = (FileNode)v.elementAt(i);
    if (newNode.compareTo(nd) < 0)
    v.insertElementAt(newNode, i);
    isAdded = true;
    break;
    if (!isAdded)
    v.addElement(newNode);
    for (int i=0; i<v.size(); i++)
    FileNode nd = (FileNode)v.elementAt(i);
    IconData idata = new IconData(FileTree1.ICON_FOLDER,
    FileTree1.ICON_EXPANDEDFOLDER, nd);
    DefaultMutableTreeNode node = new
    DefaultMutableTreeNode(idata);
    parent.add(node);
    if (nd.hasSubDirs())
    node.add(new DefaultMutableTreeNode(
    new Boolean(true) ));
    return true;
    public boolean hasSubDirs()
    File[] files = listFiles();
    if (files == null)
    return false;
    for (int k=0; k<files.length; k++)
    if (files[k].isDirectory())
    return true;
    return false;
    public int compareTo(FileNode toCompare)
    return m_file.getName().compareToIgnoreCase(
    toCompare.m_file.getName() );
    protected File[] listFiles()
    if (!m_file.isDirectory())
              return m_file.listFiles();
         try
    return m_file.listFiles();
    catch (Exception ex)
    JOptionPane.showMessageDialog(null,
    "Error reading directory "+m_file.getAbsolutePath(),
    "Warning", JOptionPane.WARNING_MESSAGE);
    return null;
    Thanks in advance
    raja

    This code shows the files in your tree
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    public class FileTree1
      extends JFrame
      public static final ImageIcon ICON_COMPUTER =
        new ImageIcon("computer.gif");
      public static final ImageIcon ICON_DISK =
        new ImageIcon("disk.gif");
      public static final ImageIcon ICON_FOLDER =
        new ImageIcon("folder.gif");
      public static final ImageIcon ICON_EXPANDEDFOLDER =
        new ImageIcon("expandedfolder.gif");
      protected JTree  m_tree;
      protected DefaultTreeModel m_model;
      protected JTextField m_display;
      public FileTree1()
        super("Directories Tree");
        setSize(400, 300);
        DefaultMutableTreeNode top = new DefaultMutableTreeNode(
          new IconData(ICON_COMPUTER, null, "Computer"));
        DefaultMutableTreeNode node;
        File[] roots = File.listRoots();
        for (int k=0; k<roots.length; k++)
          node = new DefaultMutableTreeNode(new IconData(ICON_DISK,
            null, new FileNode(roots[k])));
          top.add(node);
                            node.add( new DefaultMutableTreeNode(new Boolean(true)));
        m_model = new DefaultTreeModel(top);
        m_tree = new JTree(m_model);
                    m_tree.putClientProperty("JTree.lineStyle", "Angled");
        TreeCellRenderer renderer = new
          IconCellRenderer();
        m_tree.setCellRenderer(renderer);
        m_tree.addTreeExpansionListener(new
          DirExpansionListener());
        m_tree.addTreeSelectionListener(new
          DirSelectionListener());
        m_tree.getSelectionModel().setSelectionMode(
          TreeSelectionModel.SINGLE_TREE_SELECTION);
        m_tree.setShowsRootHandles(true);
        m_tree.setEditable(false);
        JScrollPane s = new JScrollPane();
        s.getViewport().add(m_tree);
        getContentPane().add(s, BorderLayout.CENTER);
        m_display = new JTextField();
        m_display.setEditable(false);
        getContentPane().add(m_display, BorderLayout.NORTH);
        WindowListener wndCloser = new WindowAdapter()
          public void windowClosing(WindowEvent e)
            System.exit(0);
        addWindowListener(wndCloser);
        setVisible(true);
      DefaultMutableTreeNode getTreeNode(TreePath path)
        return (DefaultMutableTreeNode)(path.getLastPathComponent());
      FileNode getFileNode(DefaultMutableTreeNode node)
        if (node == null)
          return null;
        Object obj = node.getUserObject();
        if (obj instanceof IconData)
          obj = ((IconData)obj).getObject();
        if (obj instanceof FileNode)
          return (FileNode)obj;
        else
          return null;
        // Make sure expansion is threaded and updating the tree model
        // only occurs within the event dispatching thread.
        class DirExpansionListener implements TreeExpansionListener
            public void treeExpanded(TreeExpansionEvent event)
                final DefaultMutableTreeNode node = getTreeNode(
                    event.getPath());
                final FileNode fnode = getFileNode(node);
                Thread runner = new Thread()
                  public void run()
                    if (fnode != null && fnode.expand(node))
                      Runnable runnable = new Runnable()
                        public void run()
                           m_model.reload(node);
                      SwingUtilities.invokeLater(runnable);
                runner.start();
            public void treeCollapsed(TreeExpansionEvent event) {}
      class DirSelectionListener
        implements TreeSelectionListener
        public void valueChanged(TreeSelectionEvent event)
          DefaultMutableTreeNode node = getTreeNode(
            event.getPath());
          FileNode fnode = getFileNode(node);
          if (fnode != null)
            m_display.setText(fnode.getFile().
              getAbsolutePath());
          else
            m_display.setText("");
      public static void main(String argv[])
        new FileTree1();
    class IconCellRenderer
      extends    JLabel
      implements TreeCellRenderer
      protected Color m_textSelectionColor;
      protected Color m_textNonSelectionColor;
      protected Color m_bkSelectionColor;
      protected Color m_bkNonSelectionColor;
      protected Color m_borderSelectionColor;
      protected boolean m_selected;
      public IconCellRenderer()
        super();
        m_textSelectionColor = UIManager.getColor(
          "Tree.selectionForeground");
        m_textNonSelectionColor = UIManager.getColor(
          "Tree.textForeground");
        m_bkSelectionColor = UIManager.getColor(
          "Tree.selectionBackground");
        m_bkNonSelectionColor = UIManager.getColor(
          "Tree.textBackground");
        m_borderSelectionColor = UIManager.getColor(
          "Tree.selectionBorderColor");
        setOpaque(false);
      public Component getTreeCellRendererComponent(JTree tree,
        Object value, boolean sel, boolean expanded, boolean leaf,
        int row, boolean hasFocus)
        DefaultMutableTreeNode node =
          (DefaultMutableTreeNode)value;
        Object obj = node.getUserObject();
        setText(obj.toString());
                    if (obj instanceof Boolean)
                      setText("Retrieving data...");
        if (obj instanceof IconData)
          IconData idata = (IconData)obj;
          if (expanded)
            setIcon(idata.getExpandedIcon());
          else
            setIcon(idata.getIcon());
        else
          setIcon(null);
        setFont(tree.getFont());
        setForeground(sel ? m_textSelectionColor :
          m_textNonSelectionColor);
        setBackground(sel ? m_bkSelectionColor :
          m_bkNonSelectionColor);
        m_selected = sel;
        return this;
      public void paintComponent(Graphics g)
        Color bColor = getBackground();
        Icon icon = getIcon();
        g.setColor(bColor);
        int offset = 0;
        if(icon != null && getText() != null)
          offset = (icon.getIconWidth() + getIconTextGap());
        g.fillRect(offset, 0, getWidth() - 1 - offset,
          getHeight() - 1);
        if (m_selected)
          g.setColor(m_borderSelectionColor);
          g.drawRect(offset, 0, getWidth()-1-offset, getHeight()-1);
        super.paintComponent(g);
    class IconData
      protected Icon   m_icon;
      protected Icon   m_expandedIcon;
      protected Object m_data;
      public IconData(Icon icon, Object data)
        m_icon = icon;
        m_expandedIcon = null;
        m_data = data;
      public IconData(Icon icon, Icon expandedIcon, Object data)
        m_icon = icon;
        m_expandedIcon = expandedIcon;
        m_data = data;
      public Icon getIcon()
        return m_icon;
      public Icon getExpandedIcon()
        return m_expandedIcon!=null ? m_expandedIcon : m_icon;
      public Object getObject()
        return m_data;
      public String toString()
        return m_data.toString();
    class FileNode
      protected File m_file;
      public FileNode(File file)
        m_file = file;
      public File getFile()
        return m_file;
      public String toString()
        return m_file.getName().length() > 0 ? m_file.getName() :
          m_file.getPath();
      public boolean expand(DefaultMutableTreeNode parent)
        DefaultMutableTreeNode flag =
          (DefaultMutableTreeNode)parent.getFirstChild();
        if (flag==null)    // No flag
          return false;
        Object obj = flag.getUserObject();
        if (!(obj instanceof Boolean))
          return false;      // Already expanded
        parent.removeAllChildren();  // Remove Flag
        File[] files = listFiles();
        if (files == null)
          return true;
        Vector v = new Vector();
        for (int k=0; k<files.length; k++)
                   File child = new File(dir, list);
              String name = (child.getName()) ;
              if(child.isDirectory()) add(new Node(child));
              else add(new Node(child));
    File f = files[k];
    /* if (!(f.isDirectory()))
    continue; */
    FileNode newNode = new FileNode(f);
    boolean isAdded = false;
    for (int i=0; i><v.size(); i++)
    FileNode nd = (FileNode)v.elementAt(i);
    if (newNode.compareTo(nd) >< 0)
    v.insertElementAt(newNode, i);
    isAdded = true;
    break;
    if (!isAdded)
    v.addElement(newNode);
    for (int i=0; i<v.size(); i++)
    FileNode nd = (FileNode)v.elementAt(i);
    IconData idata = new IconData(FileTree1.ICON_FOLDER,
    FileTree1.ICON_EXPANDEDFOLDER, nd);
    DefaultMutableTreeNode node = new
    DefaultMutableTreeNode(idata);
    parent.add(node);
    if (nd.hasSubDirs())
    node.add(new DefaultMutableTreeNode(
    new Boolean(true) ));
    return true;
    public boolean hasSubDirs()
    File[] files = listFiles();
    if (files == null)
    return false;
    for (int k=0; k><files.length; k++)
    if (true)
    return true;
    return false;
    public int compareTo(FileNode toCompare)
    return m_file.getName().compareToIgnoreCase(
    toCompare.m_file.getName() );
    protected File[] listFiles()
    if (!m_file.isDirectory())
              return m_file.listFiles();
         try
    return m_file.listFiles();
    catch (Exception ex)
    JOptionPane.showMessageDialog(null,
    "Error reading directory "+m_file.getAbsolutePath(),
    "Warning", JOptionPane.WARNING_MESSAGE);
    return null;

  • How can I put JTree into drop-down List of JCombobox

    I want to create a drop-down list which shows a list of nodes. When the user clicks on a node, it should open to show the leafs. Clicking on a leaf should close the ComboboxPopup and show its value. Creating a renderer only represent my tree, but I can't trap the events.
    Here is my simplified code.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.border.*;
    import java.util.*;
    public class ComboBoxTreeDemo  extends JPanel
         static JFrame frame;
         ComboBoxRenderer renderer;
         JTree tree;
         public ComboBoxTreeDemo()
              setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
              DefaultMutableTreeNode root =  new DefaultMutableTreeNode("top");
              DefaultMutableTreeNode sub1 =  new DefaultMutableTreeNode("sub1");
              DefaultMutableTreeNode sub2 =  new DefaultMutableTreeNode("sub2");
              root.add(sub1);
              root.add(sub2);
              tree = new JTree(root);
              String[] string = {"1" };
              JComboBox jcb = new JComboBox(string);
              renderer = new ComboBoxRenderer(this);
              jcb.setPreferredSize(new Dimension(100,22));
              jcb.setEditable(true);
              jcb.setRenderer(renderer);
              JPanel jpa = new JPanel();
              jpa.setLayout(new BoxLayout(jpa, BoxLayout.PAGE_AXIS));
              jpa.setAlignmentX(Component.LEFT_ALIGNMENT);
              jpa.add(jcb);
              add(jpa);
              setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
         private static void createAndShowGUI()
              JFrame.setDefaultLookAndFeelDecorated(true);
              JFrame frame = new JFrame("ComboBoxTreeDemo");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JComponent newContentPane = new ComboBoxTreeDemo();
              newContentPane.setOpaque(true);
              frame.setContentPane(newContentPane);
              frame.pack();
              frame.setVisible(true);
          class ComboBoxRenderer extends JPanel implements ListCellRenderer
              ComboBoxTreeDemo cbt;
              public ComboBoxRenderer(ComboBoxTreeDemo cbt)
                   this.cbt = cbt;
                   setLayout(new BorderLayout());
                   add(cbt.tree);
              public Component getListCellRendererComponent(JList list,Object value,int index, boolean isSelected,boolean cellHasFocus)
                   return this;
         public static void main(String[] args)
              javax.swing.SwingUtilities.invokeLater(new Runnable()
                   public void run()
                        createAndShowGUI();
    }

    Thank you for the excellent reference Peddi. I had played with the OAMessageChoiceBean component yesterday, but I was able to tell from your instructions that "Picklist Display Attribute" and "Picklist Value Attribute" really are not for binding to the database EO. That was the key piece of information that had me confused.
    In addition to adding the messageChoice component to the page, I needed to write some code to synchronize the picklist value with the corresponding code value, which I placed in am OAFormValueBean (hidden form field) which I could then bind to my application's database EO in the controller, running in the processFormRequest procedure:
    /** Synchronize the catalog code with the selected catalog name */
    protected void syncCatalogValues(OAPageContext pageContext,
    OAWebBean webBean, MyApplicationAMImpl am) {   
    OAMessageChoiceBean mcb =
    (OAMessageChoiceBean) webBean.findChildRecursive("CatalogName");
    OAFormValueBean cc =
    (OAFormValueBean) webBean.findChildRecursive("CatalogCode");
    String catalogDescription = mcb.getText(pageContext);
    if (catalogDescription != null) {
    String catalogCode = am.getCatalogCode(catalogDescription);
    cc.setValue(pageContext, catalogCode);
    Along with a little code to get the catalogCode value from the LOVVO, that's all it took.
    Thanks again. This was a great help.
    Pete

  • Set JCheckBox to gray but without disable

    Hi,
    I have a JTree with JCheckBox as the node and I would like to set the
    the square area of the JCheckbox to be gray but not disable the checkbox.
    I have tried to set the Checkbox's background or Foreground color to Gray but it doesn't really work. Anyone has any suggestion on this issue?
    Thanks!
    U0p1

    Hi,
    I am actually adding a checkbox in the TreeCellRendener :-
    public class myCheckTreeCellRenderer extends JPanel implements TreeCellRenderer
    public myCheckTreeCellRenderer(JTree tree, TreeCellRenderer renderer) {
              setOpaque(false);
              setLayout(new BorderLayout());
              this.renderer = renderer;
         add(BorderLayout.CENTER,
              renderer.getTreeCellRendererComponent(tree, "", true, true, true, 0, true));
              this.check = new JCheckBox();     
              this.check.setOpaque(true);
              this.check.setMargin(new Insets(0, 0, 0, 0));
              this.check.setBorderPaintedFlat(true);
    UIManager.put( "CheckBox.disabledForeground", Color.black);
    //I use this line to test if the checkbox changed color
    And I am trying to set the parent node (Checkbox) to gray when it's children are not all selected. The parent node has to be enable.
    I search the forum for solution and some people suggested the following:-
    UIManager.put( "CheckBox.disabledForeground", Color.black);
    but I still cannot get what I want.
    At least, I would like to see the checkbox could be filled up with it's own color but not being white or following the color of the container.
    Any help would be appreciate. I am still wondering if I need to use the Graphic class to repaint the checkbox.
    u0p1

  • JTree Object Serialization

    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    public class FileTree1 extends JFrame
    public static final ImageIcon ICON_COMPUTER = new ImageIcon("computer.gif");
    public static final ImageIcon ICON_DISK = new ImageIcon("disk.gif");
    public static final ImageIcon ICON_FOLDER = new ImageIcon("folder.gif");
    public static final ImageIcon ICON_EXPANDEDFOLDER = new ImageIcon("expandedfolder.gif");
    public String path;
    JTree m_tree;
    protected DefaultTreeModel m_model;
    protected JTextField m_display;
    public FileTree1()
    //super("Directories Tree");
    //setSize(400, 300);
    DefaultMutableTreeNode top = new DefaultMutableTreeNode(new IconData(ICON_COMPUTER, null, "Computer"), true);
    DefaultMutableTreeNode node;
    File[] roots =File.listRoots();
    for (int k=0; k<roots.length; k++)
    node = new DefaultMutableTreeNode(new IconData(ICON_DISK,null, new FileNode(roots[k])));
    top.add(node);
    node.add( new DefaultMutableTreeNode(new Boolean(true)));
    m_model = new DefaultTreeModel(top);
    m_tree = new JTree(m_model);
    m_tree.putClientProperty("JTree.lineStyle", "Angled");
    TreeCellRenderer renderer = new IconCellRenderer();
    m_tree.setCellRenderer(renderer);
    m_tree.addTreeExpansionListener(new DirExpansionListener());
    m_tree.addTreeSelectionListener(new DirSelectionListener());
    m_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    m_tree.setShowsRootHandles(true);
    m_tree.setEditable(false);
    JScrollPane s = new JScrollPane();
    s.getViewport().add(m_tree);
    getContentPane().add(s, BorderLayout.CENTER);
    m_display = new JTextField();
    m_display.setEditable(false);
    getContentPane().add(m_display, BorderLayout.NORTH);
    WindowListener wndCloser = new WindowAdapter()
    public void windowClosing(WindowEvent e)
    System.exit(0);
    addWindowListener(wndCloser);
    //setVisible(true);
    DefaultMutableTreeNode getTreeNode(TreePath path)
    return (DefaultMutableTreeNode)(path.getLastPathComponent());
    FileNode getFileNode(DefaultMutableTreeNode node)
    if (node == null)
    return null;
    Object obj = node.getUserObject();
    if (obj instanceof IconData)
    obj = ((IconData)obj).getObject();
    if (obj instanceof FileNode)
    return (FileNode)obj;
    else
    return null;
    // Make sure expansion is threaded and updating the tree model
    // only occurs within the event dispatching thread.
    class DirExpansionListener implements TreeExpansionListener
    public void treeExpanded(TreeExpansionEvent event)
    final DefaultMutableTreeNode node = getTreeNode(event.getPath());
    final FileNode fnode = getFileNode(node);
    Thread runner = new Thread()
    public void run()
    if (fnode != null && fnode.expand(node))
    Runnable runnable = new Runnable()
    public void run()
    m_model.reload(node);
    SwingUtilities.invokeLater(runnable);
    runner.start();
    public void treeCollapsed(TreeExpansionEvent event) {}
    class DirSelectionListener implements TreeSelectionListener
    public void valueChanged(TreeSelectionEvent event)
    DefaultMutableTreeNode node = getTreeNode(event.getPath());
    FileNode fnode = getFileNode(node);
    if (fnode != null)
    m_display.setText(fnode.getFile().getAbsolutePath());
    path=fnode.getFile().getAbsolutePath();
    System.out.println(path);
    else
    m_display.setText("");
    /*public static void main(String argv[])
    try
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    catch (Exception evt)
    new FileTree1();
    class IconCellRenderer extends JLabel implements TreeCellRenderer
    protected Color m_textSelectionColor;
    protected Color m_textNonSelectionColor;
    protected Color m_bkSelectionColor;
    protected Color m_bkNonSelectionColor;
    protected Color m_borderSelectionColor;
    protected boolean m_selected;
    public IconCellRenderer()
    super();
    m_textSelectionColor = UIManager.getColor("Tree.selectionForeground");
    m_textNonSelectionColor = UIManager.getColor("Tree.textForeground");
    m_bkSelectionColor = UIManager.getColor("Tree.selectionBackground");
    m_bkNonSelectionColor = UIManager.getColor("Tree.textBackground");
    m_borderSelectionColor = UIManager.getColor("Tree.selectionBorderColor");
    setOpaque(false);
    public Component getTreeCellRendererComponent(JTree tree,Object value, boolean sel, boolean expanded, boolean leaf,int row, boolean hasFocus)
    DefaultMutableTreeNode node =(DefaultMutableTreeNode)value;
    Object obj = node.getUserObject();
    setText(obj.toString());
    if (obj instanceof Boolean)
    setText("Retrieving data...");
    if (obj instanceof IconData)
    IconData idata = (IconData)obj;
    if (expanded)
    setIcon(idata.getExpandedIcon());
    else
    setIcon(idata.getIcon());
    else
    setIcon(null);
    setFont(tree.getFont());
    setForeground(sel ? m_textSelectionColor : m_textNonSelectionColor);
    setBackground(sel ? m_bkSelectionColor : m_bkNonSelectionColor);
    m_selected = sel;
    return this;
    public void paintComponent(Graphics g)
    Color bColor = getBackground();
    Icon icon = getIcon();
    g.setColor(bColor);
    int offset = 0;
    if(icon != null && getText() != null)
    offset = (icon.getIconWidth() + getIconTextGap());
    g.fillRect(offset, 0, getWidth() - 1 - offset,
    getHeight() - 1);
    if (m_selected)
    g.setColor(m_borderSelectionColor);
    g.drawRect(offset, 0, getWidth()-1-offset, getHeight()-1);
    super.paintComponent(g);
    class IconData
    protected Icon m_icon;
    protected Icon m_expandedIcon;
    protected Object m_data;
    public IconData(Icon icon, Object data)
    m_icon = icon;
    m_expandedIcon = null;
    m_data = data;
    public IconData(Icon icon, Icon expandedIcon, Object data)
    m_icon = icon;
    m_expandedIcon = expandedIcon;
    m_data = data;
    public Icon getIcon()
    return m_icon;
    public Icon getExpandedIcon()
    return m_expandedIcon!=null ? m_expandedIcon : m_icon;
    public Object getObject()
    return m_data;
    public String toString()
    return m_data.toString();
    class FileNode
    protected File m_file;
    public FileNode(File file)
    m_file = file;
    public File getFile()
    return m_file;
    public String toString()
    return m_file.getName().length() > 0 ? m_file.getName() : m_file.getPath();
    public boolean expand(DefaultMutableTreeNode parent)
    DefaultMutableTreeNode flag = (DefaultMutableTreeNode)parent.getFirstChild();
    if (flag==null) // No flag
    return false;
    Object obj = flag.getUserObject();
    if (!(obj instanceof Boolean))
    return false; // Already expanded
    parent.removeAllChildren(); // Remove Flag
    File[] files =listFiles();
    if (files == null)
    return true;
    Vector v = new Vector();
    for (int k=0; k<files.length; k++)
    //System.out.println(files[k].getName());
    File f = files[k];
    //if (!(f.isDirectory()))
    //continue;
    FileNode newNode = new FileNode(f);
    //System.out.println(newNode);
    boolean isAdded = false;
    for (int i=0; i<v.size(); i++)
    FileNode nd = (FileNode)v.elementAt(i);
    if (newNode.compareTo(nd) < 0)
    v.insertElementAt(newNode, i);
    isAdded = true;
    break;
    if (!isAdded)
    v.addElement(newNode);
    for (int i=0; i<v.size(); i++)
    FileNode nd = (FileNode)v.elementAt(i);
    IconData idata = new IconData(FileTree1.ICON_FOLDER,FileTree1.ICON_EXPANDEDFOLDER, nd);
    DefaultMutableTreeNode node = new DefaultMutableTreeNode(idata);
    parent.add(node);
    if (nd.hasSubDirs())
    node.add(new DefaultMutableTreeNode(new Boolean(false) ));
    return true;
    public boolean hasSubDirs()
    File[] files = listFiles();
    if (files == null)
    return false;
    for (int k=0; k<files.length; k++)
    //if (files[k].isDirectory())
    return true;
    return false;
    public int compareTo(FileNode toCompare)
    return m_file.getName().compareToIgnoreCase(toCompare.m_file.getName() );
    protected File[] listFiles()
    //if (m_file.isDirectory())
    //return m_file.listFiles();
    try
    return m_file.listFiles();
    catch (Exception ex)
    JOptionPane.showMessageDialog(null,"Error reading directory "+m_file.getAbsolutePath(),"Warning", JOptionPane.WARNING_MESSAGE);
    return null;

    The code which shown above is a JTree that shows complete file system.
    Please tell me how to persist the JTree Object using XMLEncoder and
    XMLDecoder for the above code.

Maybe you are looking for

  • Problem importing photos with OS 10.4.6

    I have two PowerMacs G5, one first gen G5 1.8 GHz and a Dual 1.8 GHz. I can easily download from iPhotos or directly on my HP 735 Photosmart pictures that I take when using my Dual G5. But on the other computer the photos get corrupted and are theref

  • Application can't locate Impuse Response Files

    I recently replaced my failed hard drive. After restoring from my backup, Logic can not locate impulse response files. If i am loading a preset in space designer, or loading a software instrument that has the space designer set, Logic tells me it can

  • Purchasing Info Records data upload

    Hi, I am uploading purchasing info records using LSMW and the batch input object 0060. But I do not find ESOKZ in the structures to map the Purchasing Info Records Category. Also, I have LIFNR in my source structure and also I see it in BEIN0. But th

  • R3load system copy: Error on database export

    Hello all, I am trying to do a system copy via r3load - Export and then import on a WAS 640 oracle Netweaver based system which has both ABAP and JAVA stack. The source and target system are on the same win2000 host. I am getting below errors in the

  • Impairment of Fixed Assets

    Hi All, Can any one help me in understanding what is Impairment of Fixed Assets, As you must be aware, the Institute of Chartered Accountants of India has made it mandatory for all entities to account for impairment of assets. The institute has broug