Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JTree + JScrollPane setting the scroll on top alaways.

843806Aug 11 2007 — edited Aug 12 2007
//Imports
import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.UIManager;

public class TreeExample extends 	JFrame
 {
	/**
	 * 
	 */
	private static final long serialVersionUID = -995529780260627151L;
	// Instance attributes used in this example
	private	JPanel		topPanel;
	private	JTree		tree;
	private	JScrollPane scrollPane;

	// Constructor of main frame
	public TreeExample()
	{
		 try {
		        UIManager.setLookAndFeel(
		            UIManager.getSystemLookAndFeelClassName());
		    } catch (Exception e) { }
		
		
		// Set the frame characteristics
		setTitle( "Simple Tree Application" );
		setSize( 300, 100 );
		setBackground( Color.gray );

		// Create a panel to hold all other components
		topPanel = new JPanel();
		topPanel.setLayout( new BorderLayout() );
		getContentPane().add( topPanel );

		// Create a new tree control
		tree = new JTree();

		
		// Add the listbox to a scrolling pane
		scrollPane = new JScrollPane();
		scrollPane.getViewport().add( tree );
		topPanel.add( scrollPane, BorderLayout.CENTER );
		
		
		
		
	}

	// Main entry point for this example
	public static void main( String args[] )
	{
		// Create an instance of the test application
		TreeExample mainFrame	= new TreeExample();
		mainFrame.setVisible( true );
	}
}
When you run this, scroll bar moves with the tree node you click.
How one can prevent this? let the scroll bar in the 0 position
all the time unless mouse drags the bar, itself.


I'm using MouseListener to get the x, y and the row, but due to
this moving, x, y values changes...

Any help would be nice -
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 9 2007
Added on Aug 11 2007
3 comments
177 views