Re: JScrollBar Repaint Question



While working on some sandbox code to post here I was unable to get the
same glitch to manifest itself. What I discovered after closer
examination was this:

public void paintComponent(Graphics g)
{
//textPane.setSize(getWidth()-30,getHeight()-150);
scrollPane.setSize(getWidth()-30,getHeight()-150);
textField.setSize(getWidth()-30,25);
textField.setLocation(10,textPane.getHeight()+20);
send.setLocation(getWidth()/2,textField.getY()+35);
cancel.setLocation(getWidth()/2-110,textField.getY()+35);
super.paintComponent(g);
}

I had overridden the JInternalFrame's paintComponent method (above),
and the commented line (then uncommented) was evidently resetting the
value of the attached JScrollPane's JScrollBar.

So, lessons learned:

1. Calling a repaint on the JScrollPane is sufficient for JComponent
resizing (one need not call the attached components as well).
2. Calling a repaint on the attached members of a JScrollPane seems
to reset the underlying JScrollBar's value.

Working code looks like:

public void paintComponent(Graphics g)
{
scrollPane.setSize(getWidth()-30,getHeight()-150);
textField.setSize(getWidth()-30,25);
textField.setLocation(10,getHeight()-130);
send.setLocation(getWidth()/2,textField.getY()+35);
cancel.setLocation(getWidth()/2-110,textField.getY()+35);
super.paintComponent(g);
}


Thanks for the interest/help Oliver.

.