| | |
Add a Scroller to JTree <Beginner Question>
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2008
Posts: 102
Reputation:
Solved Threads: 2
i need to a Scroll bar or JScrollPane to My Jtree... I have googled and gone through several examples, but non seemed to have worked...
Please can some one help me to solve this problem .. I simply need to have scrollers when the content of the JTree increases ..
My Code ::
Please can some one help me to solve this problem .. I simply need to have scrollers when the content of the JTree increases ..
My Code ::
Java Syntax (Toggle Plain Text)
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; public class Frame1 extends JFrame { BorderLayout borderLayout1 = new BorderLayout(); JButton jButton1 = new JButton(); JTree jTree1 = new JTree(); JSplitPane jSplitPane1 = new JSplitPane(); JPanel jPanel1 = new JPanel(); 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, 9, 218, 210)); this.add(new JScrollPane(jTree1), 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); // 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) { } }
Local P ...
•
•
Join Date: Apr 2008
Posts: 985
Reputation:
Solved Threads: 146
This works for me:
JAVA Syntax (Toggle Plain Text)
qTree = new JTree(....); qPane = new JScrollPane(qTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); contentPane.add(qPane...);
•
•
Join Date: Apr 2008
Posts: 102
Reputation:
Solved Threads: 2
•
•
•
•
This works for me:
JAVA Syntax (Toggle Plain Text)
qTree = new JTree(....); qPane = new JScrollPane(qTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); contentPane.add(qPane...);
But It doesn't work in my application. i am using JBuilder as my IDE. could you help me add the code to my application, ??
Local P ...
•
•
Join Date: Apr 2008
Posts: 102
Reputation:
Solved Threads: 2
I added this to the top of my code
But still it doesn't scroll ....
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();But still it doesn't scroll ....
Local P ...
![]() |
Similar Threads
- beginner question (Assembly)
- How to dynamically add Nodes to JTree? (Java)
- Need help to beginner's question (C++)
- C++ beginner's question (C++)
- ADO.NET question modification. (VB.NET)
- A Basic Question. . . (Windows 95 / 98 / Me)
- C compiler help (beginner question) (C++)
Other Threads in the Java Forum
- Previous Thread: Hibernate
- Next Thread: star pattern
| Thread Tools | Search this Thread |






