aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Clicking on OneTouch button will reduce the vertical scroll value by 15 if it is already at the max Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Clicking on OneTouch button will reduce the vertical scroll value by 15 if it is already at the max" Watch "Clicking on OneTouch button will reduce the vertical scroll value by 15 if it is already at the max" New topic
Author

Clicking on OneTouch button will reduce the vertical scroll value by 15 if it is already at the max

Sauk kumar
Greenhorn

Joined: Feb 20, 2013
Posts: 2
Problem is the vertical scroller will not go really down but stops just one node earlier. This works fine if you have kept the split view open. In my understanding, this is because the of following issue in java itself.

One touch expandable button of JSplitPane will reduce the vertical scroll bar value by 15 if vertical scroll bar is scrolled to maximum value and then, clicked one-touch expandable button to minimise the left pane.

Anyone can verify this by (use attached sample test) seeing GUI where scroll bar position is changed. Same can also be verified using console output.

In my opinion this is a bug and I have reported this as a bug in Oracle – Java.
but yet not accepted.

Any workaround?

import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;

/**
* Sample code.
*
* @author Saurav.Kumar
*
*/
public class OneTouchBug {

public void playUI() {
DefaultMutableTreeNode root;
root = new DefaultMutableTreeNode(0);
final JTree tree = new JTree(root);
JLabel bugLabel = new JLabel(
"<html>One touch button will reduce the vScroll <br>" +
"value by 15 if it is scrolled to maximum value and <br>" +
" then click one-touch Expandable ");
JPanel p = new JPanel();
p.add(bugLabel);
final JScrollPane jScrollPane = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
final JSplitPane sptPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jScrollPane, p);
sptPane.setDividerLocation(90);
sptPane.setOneTouchExpandable(true);
jScrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
@Override
public void adjustmentValueChanged(AdjustmentEvent e) {
System.out.println("=======================" + e.getValue());
}
});
JFrame f = new JFrame();
f.getContentPane().add(sptPane);
f.setSize(400, 200);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
populateTree(root);
tree.scrollPathToVisible(new TreePath(root.getLastLeaf().getPath()));
}

private void populateTree(DefaultMutableTreeNode root) {
DefaultMutableTreeNode currentNode = root;
int counter = 0;
while (counter++ < 9) {
DefaultMutableTreeNode nextNode = new DefaultMutableTreeNode("" + counter);
currentNode.add(nextNode);
currentNode = nextNode;
}

}

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new OneTouchBug().playUI();
}
});
}
}
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2182
    
    7
Yes, I get the same problem.

I also tried it with a JTextArea instead of a JTree and the same problem occurs.

For some reason it appears the scrollbar is moved when the width of the scrollpane is set to 0. I have no idea how to fix this.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4543
    
    5

Just in case this throws some light (or suggests a workaround -- but I couldn't find one) the aberrant behavior is seen when the horizontal scrollbar is shown/hidden. In this version of your code, try both one-touch buttons. The reduction by 15 is seen when the scroll pane is either expanded or collapsed -- and the only thing I can see that is common to both cases is the hiding of the horizontal scrollbar.

edit
The same effect is seen on the horizontal scrollbar, with a vertical split. At a guess, I would say the bug lies in the scrollpane UI delegate.


luck, db
There are no new questions, but there may be new answers.
Sauk kumar
Greenhorn

Joined: Feb 20, 2013
Posts: 2
Funny thing is that, Oracle yet not added to the bug list although I submitted this 1 week back.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4543
    
    5

Well, they've already declared that Swing is in 'maintenance mode' and this isn't a critical bug, so don't hold your breath.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Clicking on OneTouch button will reduce the vertical scroll value by 15 if it is already at the max