943,929 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1681
  • Java RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Sep 27th, 2009
0

Re: Add a Scroller to JTree <Beginner Question>


import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JTree;
import java.awt.Rectangle;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JPanel;
import java.awt.Container;

public class Frame1 extends JFrame {
    BorderLayout borderLayout1 = new BorderLayout();
    JButton jButton1 = new JButton();
    String h[]= {"DD","d","DD","d","DD","d","DD","d","DD","d","DD","d","DD","d","F"};
    JTree jTree1 = new JTree(h);
    JSplitPane jSplitPane1 = new JSplitPane();
    JPanel jPanel1 = new JPanel();
    JScrollPane jScrollPane1 = new JScrollPane();


    public Frame1() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(null);
        setBounds(0,0,500,800);


       // jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));

        jTree1.setBounds(new Rectangle(4, 31, 106, 129));
        jSplitPane1.setBounds(new Rectangle(17, 168, 179, 25));
        jPanel1.setBounds(new Rectangle(0, 6, 218, 210));
        jScrollPane1 = new JScrollPane(jTree1,
      JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
      JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        Container content = this.getContentPane();
        JScrollPane scrollpane_ind = new JScrollPane(jTree1);
  // Make the scrollbars always appear

scrollpane_ind.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  scrollpane_ind.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  int treewidth = 240;
int treeheight = 700;

//this.addComponent(this, scrollpane_ind, 5,20,treewidth,treeheight);

        this.add(new JScrollPane(jTree1), BorderLayout.CENTER);
        
        JScrollPane scrollPane = new JScrollPane(jTree1);
    content.add(scrollPane, BorderLayout.CENTER);
   //jTree1.expandRow(1);
   jTree1.setScrollsOnExpand(false);
//  this.getContentPane().add(new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,new JScrollPane(new JTree()),new JPanel()));
       // this.getContentPane().add(jScrollPane1);
        this.getContentPane().add(jTree1);
        this.getContentPane().add(jSplitPane1);
        this.getContentPane().add(jPanel1);
        jPanel1.add(jScrollPane1);
        //  this.getContentPane().add(jScrollBar1);
      //  jScrollBar1.setBounds(new Rectangle(227, 102, 17, 129));
          setVisible(true);
    }

    public static void main(String[] args) {
        Frame1 frame1 = new Frame1();
    }

    public void jButton1_actionPerformed(ActionEvent e) {

    }
}

See the bolded code segment i have added what ever you told ...
Last edited by localp; Sep 27th, 2009 at 9:28 am.
Reputation Points: 1
Solved Threads: 3
Junior Poster
localp is offline Offline
190 posts
since Apr 2008
Sep 27th, 2009
0

Re: Add a Scroller to JTree <Beginner Question>

That's the first time you showed that pert of the code, I was going on what you had shown.
So, now I see four "new JScrollPane"s and a least three places where you add a scrollpane. I have no idea what the final panel will end up showing!
It's time to go through the code and clean this all up. Just one "new" and one "add" is right.
Please also post code with [CODE=JAVA] as the opening tag.
Featured Poster
Reputation Points: 1924
Solved Threads: 952
Posting Expert
JamesCherrill is offline Offline
5,788 posts
since Apr 2008
Sep 27th, 2009
0

Re: Add a Scroller to JTree <Beginner Question>

This is a cleaned up version of my java Code.... i am lost !

JAVA Syntax (Toggle Plain Text)
  1.  
  2. import java.awt.BorderLayout;
  3.  
  4. import javax.swing.JFrame;
  5. import javax.swing.JTree;
  6. import java.awt.Rectangle;
  7. import javax.swing.JScrollPane;
  8. import java.awt.Container;
  9.  
  10. public class Frame2 extends JFrame {
  11. BorderLayout borderLayout1 = new BorderLayout();
  12. String data []={"G", "gg","G", "gg","G", "gg","G", "gg","G", "gg","G", "gg","G", "gg"};
  13. JTree jTree1 = new JTree(data);
  14. JScrollPane jScrollPane1 = new JScrollPane();
  15.  
  16. public Frame2() {
  17. try {
  18. jbInit();
  19. } catch (Exception exception) {
  20. exception.printStackTrace();
  21. }
  22. }
  23.  
  24. private void jbInit() throws Exception {
  25. getContentPane().setLayout(null);
  26. setBounds(0,0,500,800);
  27.  
  28. jScrollPane1 = new JScrollPane(jTree1,
  29. JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
  30. JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
  31. Container content = this.getContentPane();
  32. JScrollPane scrollpane_ind = new JScrollPane(jTree1);
  33.  
  34.  
  35. jTree1.setBounds(new Rectangle(19, 25, 124, 163));
  36. this.getContentPane().add(jTree1);
  37. this.getContentPane().add(jScrollPane1);
  38. jScrollPane1.setBounds(new Rectangle(133, 170, 2, 2));
  39.  
  40. setVisible(true);
  41. }
  42.  
  43. public static void main(String[] args) {
  44. Frame2 frame2 = new Frame2();
  45. }
  46. }
Last edited by localp; Sep 27th, 2009 at 9:42 am.
Reputation Points: 1
Solved Threads: 3
Junior Poster
localp is offline Offline
190 posts
since Apr 2008
Sep 27th, 2009
0

Re: Add a Scroller to JTree <Beginner Question>

You still jave multiple "new"s for scroll panes. You need exactly one.
And don't add the tree to your panel, jusr add it to the scroller and ad the scroller to the panel.
I'll be back in a few hours.
Featured Poster
Reputation Points: 1924
Solved Threads: 952
Posting Expert
JamesCherrill is offline Offline
5,788 posts
since Apr 2008
Sep 27th, 2009
0

Re: Add a Scroller to JTree <Beginner Question>

You still jave multiple "new"s for scroll panes. You need exactly one.
And don't add the tree to your panel, jusr add it to the scroller and ad the scroller to the panel.
I'll be back in a few hours.
Ok .. i badly need help !
Reputation Points: 1
Solved Threads: 3
Junior Poster
localp is offline Offline
190 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Hibernate
Next Thread in Java Forum Timeline: star pattern





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC