JTree problem (inside JSplitpane)

Hello All,
I am trying to place a Jtree inside left side of jsplitpane. But it didn't appear in it and no error or exception thrown. For testing, i placed some other component like a panel inside that left pane of splitpane and it worked fine. For further testing, when I placed my jtree's panel in applet (to test whether it has something wrong with splitpane or some other thing), it didn't appear in it too. Below is the code to illustrate what I do for my last try (in applet):
public class TRDB extends JApplet {
     public void init() {
          p("init() called");
     public void start() {
          p("start() called");
          //MainWindow mw = new MainWindow();
          //mw.setSize(400,450);
          //mw.setVisible(true);
          TreeViewPane mcp = new TreeViewPane();
          getContentPane().setLayout(null);
          getContentPane().add(mcp);
          mcp.setBounds(0,0,100,300);
          mcp.setBackground(Color.blue);
          p("start() finish!!!!!");
     private void p(String str) {
          System.out.println(str);
// TreeViewPane class
public class TreeViewPane extends JPanel {
     JTree tree;
     DefaultMutableTreeNode top;
     public TreeViewPane() {
          top = new DefaultMutableTreeNode("GDAMS");
         createNodes(top);
         tree = new JTree(top);
          tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
         //setOpaque(true);      //content panes must be opaque
     private void createNodes(DefaultMutableTreeNode top) {
         DefaultMutableTreeNode category = null;
         DefaultMutableTreeNode book = null;
         category = new DefaultMutableTreeNode("Books for Java Programmers");
         top.add(category);
         //...add more books for programmers...
         category = new DefaultMutableTreeNode("Books for Java Implementers");
         top.add(category);
}Please have a look at see if something is wrong. I just saw a blue rectangular box (depicting my jtree panel) on applet without any table in it.
Plz HELP!!

I must take some coffee or strong cup of tea. i m exhaust, really. Yah i got it what i did wrong. sorry !!

Similar Messages

  • Problem with JSplitPane

    Hi!
    I have the following problem with JSplitPane: Whenever I add two components to the splitpane and then add the splitpane to a JPanel, the left component is minimized, i.e. not visible. I always have to manually readjust the splitter in order to see the left component. I also tried a bunch of combinations of setSize, etc. but nothing seems to help.
    Here's some code:
    public void setTables(Vector<DBTable> vec)
              _panel.setSize(650, 500);
              DefaultListModel m = new DefaultListModel();
              _tableList = new JList(m);
              // _tableList.setSize(new Dimension(300, 400));
              _infoArea = new JTextArea();
              _infoArea.setEditable(false);
              // _infoArea.setSize(new Dimension(250, 300));
              MetaDataListener listener = new MetaDataListener(_infoArea, _tableList);
              _tableList.addListSelectionListener(listener);
              for (DBTable table : vec)
                   m.addElement(table);
              JScrollPane scroll1 = new JScrollPane(_tableList);
              JScrollPane scroll2 = new JScrollPane(_infoArea);
              JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, scroll1, scroll2);
              split.setSize(new Dimension(600, 480));
              _panel.add(split, BorderLayout.CENTER);
              scroll1.setPreferredSize(new Dimension(300, 400));
              scroll1.setSize(new Dimension(300, 400));
              scroll2.setPreferredSize(new Dimension(300, 400));
              scroll2.setSize(new Dimension(300, 400));
              _panel.setVisible(true);
                                         //_frame referes to a JInternalFrame and _panel surprisingly to a JPanel
              _frame.getContentPane().add(_panel, BorderLayout.CENTER);
              _frame.setVisible(true);
              split.setDividerLocation(50.0);
         }Thanks!

    Nevermind I fixed it!

  • TS1559 my wifi is grayed out... No one can fixed it...there is a problem with hardware. IC problem inside the phone. Apple have any facility like service after sales etc. Multi billion company but no priority for customers ?

    my wifi is grayed out... No one can fixed it...there is a problem with hardware. IC problem inside the phone. Apple have any facility like service after sales etc. Multi billion company but no priority for customers ? Just try to look at google search you can find lot of people who have same problem with iphone 4s. It is surly manufacturing default. Is that apple reputation lounching New virsion Iphone with diffective hardware.

    Plz dont give me idea setting>reset>reset network configration .... I already did it..... give me proper solution... who can replace default hardware from my iphone?????????????????????

  • JTree: Problems updating the nodes size

    Hi,
    I'm trying to update the content of a JTree and I wonder how it
    really works, since the paint() method doesn't seem to call the
    renderer.
    My situation: Imagine a JPanel splited in two by a JSplitPane. In
    the left is the tree. Each node in the tree shows two panels, one
    aligned to the left, and another to the right. I need that the panel
    containing the two use all the available space in the left part of the
    Split panel.
    My solution: I pass the left JPanel to the tree renderer, so that
    it can get the width from it (inside the
    getTreeCellRendererComponent()) to build the return JPanel with the
    correct size. My logic is that since each time you move the JSplitPane
    the JTree paint() method is invoked the renderer can return the
    correct JPanel with the correct size that will be painted then in the
    screen.
    My problem: Doens't work. When I render the tree, the renderer is
    invoked, but it doesn't change its size (I can change the color based on the width, but not the node size). Only when I collapse & expand a node, it correctly takes into account the .setPreferredSize() and returns the JPanel with the correct size.
    The only way I found to update the tree involves to catch the
    JSplitPane event and call updateUI() in the tree, something that, I
    think, it's certainly not the correct way to do it.
    Any explanation of why this doesn't work would be really great. Any
    pointer to a web resource explaining in deep how Swing components work (specially the JTree) would be a godsend.
    Thanks,
    - Juancho

    My situation: Imagine a JPanel splited in two by a JSplitPane. Got it.
    In the left is the tree. In the left side of the JSplitPane is a JTree.
    Each node in the tree shows two panels,Maybe... on the right side of the JSplitPane are two Panels in which the data depends on which node is selected in the JTree???
    Maybe... you have a custom TreeCellRenderer which displays a pair of panels in place of the standard JLabel???
    one aligned to the left, and another to the right. To the left of what??? To the right of what???
    I need that the panel containing the two use all the available
    space in the left part of the Split panel.Panel containing the two what??? I thought the left part of the SplitPanel contained a JTree???

  • Cursor problem inside a JInternalFrame

    Hi Everyone,
    I encountered a strange problem working with JInternalFrames. The cursor doesn't change to a resize cursor when it should (for example when resizing a JSplitPane or a JTable inside a JInternalFrame).
    On the main Frame everything just works fine.
    I have tried to change the cursor manually on some events but this didn't work at all. The cursor just didn't change.
    Does anyone have an idea?
    (I must use JDK 1.3.1, probably this problem is solved in 1.4)
    Thanks in advance!
    Boris

    Hi,
    for the cursor change to work, I think you must ensure
    that the concerned internal frame is active &
    selected... is it the case ?I have tried the following:
    mInternalFrame.setSelected(true);
    mInternalFrame.setEnabled(true);
    mDesktopPane.setSelectedFrame(mInternalFrame);The internal frame is selected but the cursor still doesn't change. How do you set the internal frame active?

  • JTree problem displaying nodes

    I have created a GUI, in which part of it allows the user to view files in a selected folder in a JTree format.
    The tree only shows selected files with certain extensions (such as ".txt", ".doc", etc.. see code below)
    I'll try to show what it looks like, for example:
    - RootFolder
        - SomeOpenFolder
            - someFile
            - anotherFile
        + SomeClosedFolder
        - File_in_RootFolder
        - Another_file_in_RootFolder Anyhow, when I shipped it to my boss he occasionally cannot view the full file names..
    for example:
    - RootFolder
        - SomeOp....
            - some....
            - anothe...
        + SomeClo...
        - File_in_R...
        - Another_fil...I have the JTree inside a JScrollPane with horizontalScrollBarPolicy set to "AS_NEEDED"
    I have run several tests, with both LONG and SHORT names... and it all works just fine for me
    For example:
    - RootFolder
        - SomeOpenFolder
            - someFile
            - anotherFile_With_A_VERY_VERY_VERY_VERY_LOOOOOOOOOOOOOOOOOOOONG_NAME
        + SomeClosedFolder_With_A_VERY_VERY_VERY_VERY_LOOOONG_NAME
        - File_in_RootFolder
        - Another_file_in_RootFolder And i am able to scroll left&right to view the full name within the scroll panel.
    But for some reason, on my Bosses computer sometimes it has the full name,
    and other times it cuts the name short with "FolderNa..."
    Is anyone aware of why such a problem could happen?
    Here is my code setting up the tree.
    public void setMyTree(String myFolder)
    File rootFile = new File(myFolder);
            JTree targetTree = new JTree(TreeSetup(rootFile, InputIncludeFilter()));
            targetTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
            targetTree.setCellRenderer(new TreeCellRenderer() {
                  public Component getTreeCellRendererComponent(JTree tree, Object value,
                                boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
                      JLabel label = new JLabel(value.toString());
                      TreePath p = tree.getPathForRow(row);
                      if(p != null){
                          File node = getInputFile(p);                    
                      if (selected) {
                             label.setOpaque(true);
                             label.setBackground(tree.getBackground().darker());
                          return label;
                  private File getInputFile(TreePath path) {
                      StringBuffer fName = new StringBuffer();
                        boolean isroot = true;
                        for (Object s : path.getPath()) {
                                  fName.append(s + File.separator);                          
                      return new File(getUserDomain()+File.separator +
                                 fName.toString().substring(0, fName.toString().length() - 1));
    }Any ideas? Do would it help to see my method "InputIncludeFilter()"

    DefaultTreeCellRenderer extends from JLabel, so whatever you are doing to the JLabel you create you can do to the DefaultTreeCellRenderer too.
    This would be more like it:
           targetTree.setCellRenderer(new DefaultTreeCellRenderer() {
                  public Component getTreeCellRendererComponent(JTree tree, Object value,
                                boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
                     super.getTreeCellRendererComponent(tree,value,selected,expanded,leaf,row,hasFocus);
                      TreePath p = tree.getPathForRow(row);
                      if(p != null){
                          File node = getInputFile(p);                    
                      if (selected) {
                             this.setOpaque(true);
                             this.setBackground(tree.getBackground().darker());
                          return this;
                  }

  • An Expandable JTree Problem

    Hi, I'm relatively new to creating JTree components, now I have looked at many examples, and this one is nearest (i can see) to how I want my Jtree to look, however it doesn't behave in a way which I would like!
    Firstly, I can set the root node to have as many folders as i want, however they only mirror whats in the first root node, I dont want this - I want to be able to create about 5/6 different roots that will yield different results - I also want after each time you click on a folder, which will ask a question about a patient i.e. "Has the patient a head injury" - click on this then it should come up with "3" more different choices, so altogther want it about 5 deep.
    However, this is what I've got so far - but like I say, its not yielding the results I want, does anyone know how to modify this or can anyone point me in the right direction by starting me off a bit, that would be great!
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    public class SelectableTree extends JFrame
                                implements TreeSelectionListener {
      public static void main(String[] args) {
        new SelectableTree();
      private JTree tree;
      private JTextField currentSelectionField;
      public SelectableTree() {
        super("Clinical Information Help System");
        WindowUtilities.setNativeLookAndFeel();
        addWindowListener(new ExitListener());
        Container content = getContentPane();
        DefaultMutableTreeNode root =
          new DefaultMutableTreeNode("Begin Clinical Questions");
        DefaultMutableTreeNode child = null;
        DefaultMutableTreeNode parent = null;
        DefaultMutableTreeNode grandChild = null;
        DefaultMutableTreeNode grandParent = null;
        DefaultMutableTreeNode child2 = null;
        DefaultMutableTreeNode parents = null;
        for(int grandParentIndex=1; grandParentIndex < 2; grandParentIndex++) {
          grandParent = new DefaultMutableTreeNode("[Does Patient Have Back Pains?] " + grandParentIndex);
          root.add(grandParent);
          for(int parentIndex =1; parentIndex < 3; parentIndex++) {
            parent = new DefaultMutableTreeNode("[Does the patient also have leg pain?] " + parentIndex +
                                         "." + parentIndex);
            grandParent.add(parent);
            for(int childIndex =1; childIndex < 3; childIndex++) {
             child = new DefaultMutableTreeNode("[are the pains in the lower back?] " + childIndex +
                                         "." + childIndex);
              parent.add(child);
              child2 = new DefaultMutableTreeNode("patient over 60?" + childIndex +
                    "." + childIndex);
              child.add(child2);
            for(int grandChildIndex =1; grandChildIndex < 3; grandChildIndex++) {
               grandChild = new DefaultMutableTreeNode("[Does patient have bladder and/or bowel incontinence?] " + grandChildIndex +
                                            "." + grandChildIndex);
                 child.add(grandChild);
            for(int childIndex = 1; childIndex < 3; childIndex++) {
                child = new DefaultMutableTreeNode("[Has Patient suffered either: appitite/wieght loss/fever?]" + childIndex +
                                             "." + childIndex);
                child = new DefaultMutableTreeNode("[Has pain been 4-6wks leg pain? OR 3-6mths low-back pain?]" + childIndex +
                        "." + childIndex);
                  grandChild.add(child);
        tree = new JTree(root);
        //tree = new JTree(root2);
        tree.addTreeSelectionListener(this);
        content.add(new JScrollPane(tree), BorderLayout.CENTER);
        currentSelectionField = new JTextField("Current Selection: NONE");
        content.add(currentSelectionField, BorderLayout.SOUTH);
        setSize(400, 400);
        setVisible(true);
      public void valueChanged(TreeSelectionEvent event) {
        currentSelectionField.setText
          ("Current Selection: " +
           tree.getLastSelectedPathComponent().toString());
    }

    I'm not really sure what your problem is, for I don't see what you mean by "mirror". If it is you have but one root node, but wanted to have many instead, then you'd simply need to call setRootVisible(false); on the tree.
    As a sidenote, I don't think it's a really good UI for what you're doing, but after all, I haven't got the whole picture.
    Now, what is it you mean by: its not yielding the results I want ?

  • JTree problem

    I posted a simillar problem not long ago but didn't explain properly.
    The code below displays a JFrame with a JScrollPane containing a JTree with just a root node ("root").
    At the bottom of the frame is a button that when pressed re-initialises the JTree with no arguments (line 42). Hence once the button is clicked the JTree should have some elements in it (those default ones : colours, sports, food).
    However, the reinitialised JTree is not displayed. What's the problem?
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    class Test extends JFrame implements ActionListener {
         private JScrollPane            treeScrollPane;
         private JTree                  tree;
         private DefaultMutableTreeNode root;
         private JButton                runButton;
         public Test() {
              super("Test");
              this.tree = new JTree(this.root = new DefaultMutableTreeNode("root"));
              this.treeScrollPane = new JScrollPane(new JTree());
              this.treeScrollPane.setBorder(BorderFactory.createCompoundBorder(
                   BorderFactory.createTitledBorder("Tree panel"),
                   BorderFactory.createEmptyBorder(5,5,5,5)));
              this.runButton = new JButton("click me");
              this.runButton.addActionListener(this);
              Container contentPane = getContentPane();
              contentPane.setLayout(new BorderLayout());
              contentPane.add(this.treeScrollPane, BorderLayout.CENTER);
              contentPane.add(this.runButton,      BorderLayout.SOUTH);
              this.setSize(300, 400);
              this.setLocationRelativeTo(null);
              this.setDefaultCloseOperation(EXIT_ON_CLOSE);
              this.setVisible(true);
         public void actionPerformed(ActionEvent e) {
              Object source = e.getSource();
              if (source == this.runButton) {
                   System.out.println("DEBUG : button clicked");
                   this.tree = new JTree();
                   this.tree.expandPath(new TreePath(this.tree.getModel().getRoot()));
         public static void main(String args[]) {
              try {
                   UIManager.setLookAndFeel(
                        UIManager.getSystemLookAndFeelClassName());
              } catch (Exception e) {
                   System.out.println(e.getMessage());
              new Test();
    }

    The problem is that the scrollpane is still displaying the first tree.
    To fix this, you'll need to add the following line to your actionPerformed method:
    treeScrollPane.setViewportView(tree);(I think you might be a litle confused by the difference between an object and a reference. The scrollpane holds a reference to the first tree you create. Then you create a new tree and assign it to your this.tree reference, but the scrollpane's reference is stil pointing to the first tree. If this explanation is all mumbled up it's because I haven't had my first cup of coffee yet :-)

  • Big problem with JSplitPane

    Hello,
    I feel I'm going mad with Swing.
    I have a main main JTabbedPane: main.
    First component: JEditorPane : source
    Second Component: JPanel : view( = new JPanel())
    In view I have:
    JPanel toolbox to NORTH and JSplitPane: ds to CENTER.
    In ds I have:
    Left component: new JScrollPane(design) where design=new JPanel()
    Right component: JSplitPane(....) : called pe
    First problem:
    In ds the left component is too small. I tried to use all functions available , no result. I want the right component(pe) to have width=200, but no chance. It is too big. Why?
    Second problem:
    The scrolls are not appearing on the left at the ds(JSplitPane)
    Third problem:
    I add different components to design JPanel(the one which is placed into a JScrollPane which is related to the second problem) but nothing happens. They won't appear on design which is the same and without no scrolls.
    Please help me solve this Swing mistery.
    Thank you all.

    The split pane, by default, will size its two halves based on their preferred sizes. If the combined preferred sizes are too small (for the size of the spilt pane) then the extra space is distributed based on JSplitPane's resize weight. The default is to add the extra to the right hand side, see JSplitPane.setResizeWeight for an explanation. If you really want the right hand side to be exactly 200 pixels then you can programmatically move the divider to a location that would leave the right hand side to be 200. Or you can set the preferred size of the component you place there to 200 and set a resize weight that will give the extra space to the left instead of the right.
    I am not sure about why the scroll bars are not showing up. Does it need scroll bars?
    May I suggest creating a simple demo app to show the problem? Often I solve my own problems doing this otherwise you have some code for us to look at and play with.
    Ian

  • Problem with JSplitPane.setDividerPosition

    An applet has a split panel, a list of items shown to the left and a map display to the right.
    The problem I'm getting is that the divider bar insists on starting life in the middle.
    My intialisation looks like this:
        protected void initGui() {
            Container content = getContentPane();
            JMenuBar bar = new JMenuBar();
            setupMenu(bar, MK_MENU_DATASTORE, dataStoreMenu);
            setJMenuBar(bar);
            content.setBackground(new Color(0xfffeff));
            layerList = new JPanel();
            layerList.setLayout(new BoxLayout(layerList, BoxLayout.Y_AXIS));
            layerList.add(Box.createVerticalGlue());
            mapPanel = new ViewPanel();
            JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, layerList, mapPanel);
            split.setDividerLocation(ViewLayer.LAYERBOX_WIDTH);
            split.validate();
            content.add(split);
            validate();
        }Now the divider location I set seems to get squirreled away somewhere, because when I click the bar with the mouse it jumps to the correct position but it refused to initialise to the right position.

    Oops! Spotted it.

  • JTree - problems with names of elements

    I have a Jtree thats populated with expandable elements. These elements are loaded on startup, but some of the elements don't get their full names, just i.e "dem..." instead of "demo3". WHen I expand the node, the full name appears, and remains.
    Anyone know what this could be?
    The problem is really often associated with nodes with names containing "m" ..

    By default the tree node renderer is JLabel.
    It look like you are not using pack() or validate().
    It depend also the layout manager you are using.
    In one word, it seems the JLabel has dimension too short.
    Can only show 3 to 4 char. that is why "demo3" show as "dem..."
    Try have some node name like "WWWWW", if you see "WW..." or "WWW..."
    Then that is the problem. ( Not as you thought: only "m" has problem )

  • Problems resizing JSplitPane

    I have a JSplitPane with a Canvas3D on one side. It won't allow the split pane to be resized to make the canvas smaller. It will allow the splitpane to be resized to make the canvas larger, though.
    Is there a way to fix this?
    Thanks,
    Brian.

    The solution for this problem is a little bit tricky:
    - put a JScollPane (not a ScrollPane!) to one side of the JSplitPane and set the scrollbar policies to ..._SCROLLBAR_NEVER
    - put your Canvas3D into the ViewPort of the JScrollPane
    - create a PropertyChangeListener which listens to the JScrollPane and the JSplitPane
    Now you can use the JSplitPanes but it looks ugly because the size of the Canvas3D doesn't changes. So every time a PropertyChange event occures you have to calculate the size of the Canvas3D using your JFrame's size and the JSplitPanes diver location and change the Canvas3D's size using setSize().
    Oxygenic

  • JTree Problem again

    Deat 7rst,
    Sorry, I want to ask you about the same problem.
    if I want to display a difference components from difference node in JTree, how the code I must use?
    I already understand about the code that you give to me. But I still confuse if many nodes in JTree to perform difference panel with many components each of its. The components beside JTextField.
    Thanks

    I have used THE SEARCH BOX - can't find nothing about editable JList, there are only references for editable Trees and Tables.
    Do anybody have concrete idea (the best would be some code), or should I reconcile myself with the JTable solution?

  • JTree Problem - Need help

    Hi,
    I am using a JTree to which I have set my own TreeModel and TreeSelectionListener (overidden all the methods for both). Wehn I add a new node to the tree, the node appears but the text for the node does not.
    (e.g if the text is "ABCD", what appears is "AB..."). I called a tree.repaint(). It does not solve my problem.
    A tree.updateUI() does solve my problem, but it throws a NullPointerException on every selection in the tree. I am trying to refresh the tree in the selSelection() method of the selection model.
    Is there any other way?
    Thanks in advance,
    Achyuth

    Try adding this when you add a node. Don't have time to check it so not quite sure its what you're looking for but I remember having this prob before and I think this is what I did:
    EventListener[] listeners = ((DefaultTreeModel)tree.getModel()).getListeners(TreeModelListener.class);
    for (int i = 0; i < listeners.length; i++) {
              ((TreeModelListener)listeners).treeNodesChanged(new TreeModelEvent(this, new TreePath(node.getPath())));
    Alex

  • Texfield autoSize problem inside embedded movie

    Hi guys!
    I have a strange problem..
    I have a flash file inside which i have a movieclip. I am
    loading an external swf file into this movieclip using the
    loadMovie script.
    the external swf has a couple of texfields that load in
    content from an XML file. These are autosized using the autosize
    script. When i run this external swf on its own the resize
    works....
    The resize does not work when the swf is loaded into my main
    flash file!!!
    HAAAALLP!!..

    Can you show the code you use when setting the autoSize?
    There may be some _root reference or something that no longer
    stands when the file is embedded inside another.

Maybe you are looking for

  • Addressbook and Messages not working with iPhoto-Faces

    Hey I've set up ML with an clean-install. I also set up iPhoto 11 (Mac-App Store updates installed directly after installing iPhoto 11) with my existing picture-library (upgrade of the library on first run was successfully). My problem: I cannot sele

  • Insert Editing, Why Won't Clips Appear In The Timeline?

    Every time I attempt an insert edit, either via the "downward arrow" symbol or via "W" on the keyboard the clip appears in a secondary time/storyline below the Timeline, with a blank space in the main Timeline of exactly the same duration as the clip

  • How do I force iPhone to store pics in Photo Stream instead of  Cameral Rolld

    Sometimes the pictures are stored in Cameral Roll and sometimes Photo Stream. But with Camera Roll the photos do not automatically load into iPhoto.

  • A Scenario to map

    Dear Team, Employee payroll is monthly and paid the applicable Basic, allowances etc. What is the recommended solution for the below scenario. In some cases, from a particular period, the employee to receive ONLY the 50% of Basic Salary. All other al

  • POST method

    There are two procedures: Procedure ShowR(n1 Varchar2 Default Null) Is Begin Htp.P(N1); Owa_Util.Print_Cgi_Env; Exception When Others Then Htp.P('Error'); End; Procedure PostMtd Is Begin Htp.HtmlOpen; Htp.P(''); Htp.Script('function F() {fm.submit();