The list of methods to do JScrollPane are organized into topic(s).
void
addStyle(JScrollPane jScrollPane, String labelName) add Style
Border line = BorderFactory.createLineBorder(Color.LIGHT_GRAY);
TitledBorder titled = BorderFactory.createTitledBorder(line, labelName);
titled.setTitleFont(new Font("Verdana", 0, 13));
titled.setTitleColor(new Color(213, 225, 185));
Border empty = new EmptyBorder(5, 8, 5, 8);
CompoundBorder border = new CompoundBorder(titled, empty);
jScrollPane.setBorder(border);
jScrollPane.setForeground(new Color(143, 170, 220));
...
JScrollPane
createScrollPane(JComponent content) creates a scrollpane with the given component embedded.
JScrollPane scrollPane = new JScrollPane(content, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
return scrollPane;
JScrollPane
createSelfManagedScrollPane(final Component view, final JComponent parentToRevalidate) Creates and returns a scroll panel which wraps the specified view component.
The returned scroll panel disables vertical scroll bar, and only displays the horizontal scroll bar when the view does not fit into the size of the view port.
final JScrollPane scrollPane = new JScrollPane(view);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
scrollPane.getHorizontalScrollBar().setPreferredSize(new Dimension(0, 12));
scrollPane.getHorizontalScrollBar().setUnitIncrement(10);
final ComponentListener scrollPaneComponentListener = new ComponentAdapter() {
@Override
public void componentResized(final ComponentEvent event) {
scrollPane.setHorizontalScrollBarPolicy(
...
void
defaultAutoScroll(JComponent comp, Point cursorLocn) Implements autoscrolling.
Rectangle visible = comp.getVisibleRect();
int x = 0, y = 0, width = 0, height = 0;
if (cursorLocn.x < visible.x + AUTOSCROLL_INSET_SIZE) {
x = -SCROLL_AMOUNT;
width = SCROLL_AMOUNT;
else if (cursorLocn.x > visible.x + visible.width - AUTOSCROLL_INSET_SIZE) {
x = visible.width + SCROLL_AMOUNT;
...
Insets
defaultGetAutoscrollInsets(JComponent comp) default Get Autoscroll Insets
Rectangle visible = comp.getVisibleRect();
Dimension size = comp.getSize();
int top = 0, left = 0, bottom = 0, right = 0;
if (visible.y > 0) {
top = visible.y + AUTOSCROLL_INSET_SIZE;
if (visible.x > 0) {
left = visible.x + AUTOSCROLL_INSET_SIZE;
...
JScrollPane
findScrollPane(Component c) find Scroll Pane
while (c != null) {
if (c instanceof JScrollPane) {
JScrollPane sp = (JScrollPane) c;
if (((sp.getHorizontalScrollBar() != null) && sp.getHorizontalScrollBar().isVisible())
|| ((sp.getVerticalScrollBar() != null) && sp.getVerticalScrollBar().isVisible())) {
return sp;
c = c.getParent();
return null;