R
R W
I am trying to figure out what would make a command work in one place
but not in another. In my code I have a scrollPane initialized to hold
some text.
myTextPane = new JTextPane();
StyledDocument doc = myTextPane.getStyledDocument();
try {
doc.insertString(doc.getLength(),
"stuff\n\n\n\n\n\n\n\n\nstuff 2\n\n\n\n\n\n\n\n\n\n\n\n\nstuff 3\n",
null);
} catch (BadLocationException e1) {
e1.printStackTrace();
}
JPanel myPanel = new JPanel(new BorderLayout());
myPanel.add(myTextPane);
htmlView = new JScrollPane(myPanel);
htmlView.getVerticalScrollBar().setValue(0); //The stubborn command!
After the code is first set up the scroll bar is scrolled all the way
to the bottom. Then I have a listener that runs.
public void valueChanged(TreeSelectionEvent e) {
htmlView.getVerticalScrollBar().setValue(0);
}
When you click on something all it does is run the command to set the
scroller to the top. The first time it doesn't work but in the listener
it works! What is going on? It seems like something different is
happening when you click on something in the gui than what is happening
when you set up the JScrollPane at first. What is making it run the
setValue command the second time but not the first? Is there some
sneaky sort of refresh going on that I haven't figured out?
Thanks for any thoughts. I've been banging my head on this scroll
problem for a while.
but not in another. In my code I have a scrollPane initialized to hold
some text.
myTextPane = new JTextPane();
StyledDocument doc = myTextPane.getStyledDocument();
try {
doc.insertString(doc.getLength(),
"stuff\n\n\n\n\n\n\n\n\nstuff 2\n\n\n\n\n\n\n\n\n\n\n\n\nstuff 3\n",
null);
} catch (BadLocationException e1) {
e1.printStackTrace();
}
JPanel myPanel = new JPanel(new BorderLayout());
myPanel.add(myTextPane);
htmlView = new JScrollPane(myPanel);
htmlView.getVerticalScrollBar().setValue(0); //The stubborn command!
After the code is first set up the scroll bar is scrolled all the way
to the bottom. Then I have a listener that runs.
public void valueChanged(TreeSelectionEvent e) {
htmlView.getVerticalScrollBar().setValue(0);
}
When you click on something all it does is run the command to set the
scroller to the top. The first time it doesn't work but in the listener
it works! What is going on? It seems like something different is
happening when you click on something in the gui than what is happening
when you set up the JScrollPane at first. What is making it run the
setValue command the second time but not the first? Is there some
sneaky sort of refresh going on that I haven't figured out?
Thanks for any thoughts. I've been banging my head on this scroll
problem for a while.