> Hi All,
> is there any possible way to know if the jScrollbar
> intend to show a scrollbar.
> i need this event in order to activate other
> scrollbar.
> is there any event that can give me this
> information?
>
> TIA
I don't believe there is...
I would normally just set the scrollbars to always show
something like this?
(run the program, hit enter 5 or 6 times)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Testing
{
public void buildGUI()
{
JTextArea ta = new JTextArea(5,10);
JScrollPane sp = new JScrollPane (ta);
JFrame f = new JFrame();
f.getContentPane().add(sp);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
sp.getVerticalScrollBar().addComponentListener(new ComponentAdapter(){
public void componentShown(ComponentEvent ce){
System.out.println("ScrollBar kicked in");
}
});
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable(){
public void run(){
new Testing().buildGUI();
}
});
}
}
> my problem is that my vertical scrollbar are not visible i need only to know that "we need a scroll bar " and thats all.
Add a DocumentListener to the Document of the text area. Whenever an event is fired you comare the preferred size of the related text area with the size of the scroll pane.
Note, make sure the above code is wrapped in a SwingUtilities.invokeLater() so the code executes after the Documents has been updated.
Or you may be able to add a ComponentLIstener to the text area to see it the size changes as text is added or removed from the Document and then compare the size against the scroll pane.
> how can i know when i leave the scrollbar area?
No idea what this means.