//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 -