JScrollPane scroll bar trouble on rebuild

I've been working on this for hours (about 4 hours now) without finding the right solution, so maybe someone can help. I searched through a few pages of the forum but didn't see this exact issue. And the tutorial online doesn't help much.
I have a JPanel in a JScrollPane in a JFrame. The JFrame has it's height reduced if its over a particular size (in the test case, it gets reduced). When it first loads, it's fine. However, if I rebuild the whole JFrame (some event causes the JPanel content to change, and refresh() is called again), the window remains the same size but the vertical scroll bar extends off the bottom of the frame. If I manually resize the frame with the mouse (even by 1 pixel), the scroll bar updates and looks correct again. What is the correct way to do this? Calling revalidate() on the JScrollPane after doing the setSize() doesn't do anything. And why does it work the first time when the JFrame is first built through the Constructor?
example code:
public class MyFrame extends JFrame {
    public MyFrame() {
        super();
        refresh();
    private void refresh() {
        JPanel jp = new JPanel();
        jp.setLayout(new SpringLayout());
        // add some stuff to jp
        JScrollPane scrollPane = new JScrollPane(
            JScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED
        scrollPane.getViewport().add(jp);
        setContentPane(scrollPane);
        pack();
        if (getHeight() > MAX_HEIGHT) {
            setSize(getWidth(),MAX_HEIGHT);
}

When you have changed the content, call getRootPane().validate(); instead of pack(), as in this slightly modified version of your sample program:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MyFrame extends JFrame implements ActionListener {
    private static final int MAX_HEIGHT = 100;
    public MyFrame() {
        super();
        refresh(true);
    public static void main(String[] args) {
        MyFrame myFrame = new MyFrame();
        myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        myFrame.setVisible(true);
    private void refresh(boolean pack) {
        JPanel jp = new JPanel();
        jp.setLayout(new BoxLayout(jp,BoxLayout.Y_AXIS));
        JButton refreshButton = new JButton("Refresh");
        refreshButton.setActionCommand("refresh");
        refreshButton.addActionListener(this);
        jp.add(refreshButton);
        jp.add(new JLabel("Hello"));
        jp.add(new JLabel("There"));
        jp.add(new JLabel("Why"));
        jp.add(new JLabel("Doesn't"));
        jp.add(new JLabel("Refresh"));
        jp.add(new JLabel("Work"));
        JScrollPane scrollPane = new JScrollPane(
            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED
        scrollPane.getViewport().add(jp);
        setContentPane(scrollPane);
        if (pack) {
            pack();
        else {
            getRootPane().validate();
        if (getHeight() > MAX_HEIGHT) {
            setSize(getWidth(),MAX_HEIGHT);
    public void actionPerformed(ActionEvent ae) {
        refresh(false);
}

Similar Messages

  • JScrollPane  - scroll bar not visible

    I'm writing a graphical chat application where the user presses buttons to insert images into their message. The buttons reside in a JPanel with a GridLayout. As i have more buttons than can be physically seen on the screen I'm trying to use a JScrollPane encapsulated in the JPanel so that the user can scroll down the button list to select appropriate symbols. The problem i'm having is that the scroll bars do not appear so the user can only use symbols which are visible. Here is the code for what i'm trying to acheive.
    buttonPanel.setLayout(new GridLayout(9,3));
    buttonPanel.add(Button1);
    buttonPanel.add(Button2);
    buttonPanel.add(Button3);
    buttonPanel.add(Button4);
    .....etc to around Button100
    buttonHolder.add(new JScrollPane());
    buttonHolder.setPreferredSize(new Dimension(400,400));
    buttonHolder.setMaximumSize(new Dimension(400,400));I think I'm missing something from the add JScrollPane bit but I'm not sure what exactly!
    PLEASE HELP - this is for my third year dissertation and is the last bit I need to do before it is finished.

    First, you need to add your panel to the JScrollPane object. Then you add the JScrollPane object to the frame, not the panel itself.
    As for setting the scrollbars of the JScrollPane, you could try setVerticalScrollbarPolicy() and setHorzontalScrollbarPolicy().

  • Swing (JScrollPane - scroll bar) help

    Hello all..
    I am new user in Swing. Currently I am developing a program using JSCrollPane. I have to draw a kind of chart in it. Therefore as a drawing media, I used the JPanel, in which I put it inside my JScrollPane. Then.. since my graphic is long.. then I set the
    setHorizontalScrollBarPolicy value to ALWAYS. Then I put my JPanel using the following commands :
    this.jScrollPane1.setViewportView(this.jPanel2);
    this.jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    Fyi, my JPanel size is set to be wider than the jScrollPane3 size. Nevertheless.. during the run time the horizontal scroll bar is not shown. I am completely loss on how to solve this. Does anyone has any clue or solution for this problem. Thank you very much in advance.
    Kariyage.

    Fyi, my JPanel size is set to be wider than the jScrollPane3 sizeYou should use panel.setPreferredSize(...) not panel.setSize(...);

  • JScrollPane - SCROLL BAR width?

    I currently have a JEditorPane inside a JScrollPane
    Whenever I have content that exceeds the height of the JScrollPane, I get a scroll bar on the right. Unfortunately, I think this scroll bar is a bit TOO THICK and is unsightly. Is there anway I can explicitly specify the WIDTH of this scroll bar if and when it's needed? THANKS!

    Try this when creating the layout:
    JScrollBar vsb = JScrollPane.getVerticalScrollBar();
    Dimension sbsize = vsb.getSize();
    Dimension newsbsize = new Dimension(sbsize.getWidth() - 5 , sbsize.getHeight() );
    vsb.setPreferredSize(newsbsize);
    You could also try setting the Maximum size using vsb.setMaximumSize(newsbsize);
    Adjust the 5 in the new Dimension line to control how much smaller the witdh is from normal.

  • Scroll Bar Troubles, Please Help.

    When In A WebPage, I Have No Scroll Bars, And The Up And Down Arrows Will Not Scroll The Page Either. The Only Way I Can Scroll Is By Dragging The Screen Up And Down By Highlighting And It's Rather Bugging Now. I'm New To Macs By Two Weeks So Please Please Help.
    ThankYou.

    What browser are you using? Do you get this condition on all web pages you access?

  • ITunes 11 scroll bar trouble

    Hi folks,
    this concerns iTunes 11.1.3 for Mac: when in the iTunes store to view my purchased items, I cannot use the left scroll bar (artist listing).  The said scroll bar is visible only when the pointer rests on an item - the moment I approach the scroll bar with the pointer in order to scroll up or down the list, it simply disappears. Does anyone know a fix for this bug?  Please, let me know.  Thanks!
    Frank M.

    You don't have to scroll with your arrow directly on the bar.  Scroll works when your arrow is positioned in this area:

  • Scroll bar trouble in filmstrip mode

    In horizontal filmstrip mode (Bridge 2.1.0.100), the right end of the horizontal scroll bar is not visible. If I make the Bridge window smaller than full screen, I can drag the slider out of sight beyond the right side of the Bridge window, but not far enough to see all the files. The right side of the Bridge window appears to be otherwise normal.
    What's happening?

    Thanks again Curt,
    I seem to have fixed it. I opened the pop-out menu associated with the filmstrip button(#1)in the lower-right-hand corner of the window and re-selected Horizontal Filmstrip. That fixed the scroll bar (displayed the right edge of it). I couldn't increase the screen resolution because I was already at the native resolution for the (flat-panel) monitor. When I had the Bridge window open to less than screen size, it was very strange to drag the scroll bar outside the Bridge window where it disappeared. I could move it even though I couldn't see it.

  • Horizontal scroll bar at top in JScrollPane

    Hi,
    How can i get the horizontal scroll bar to be on the top instead of bottom
    here is my code
    TableModel tableModel = new TableModel(totalData,
    columnHeader);
    JTable table = new JTable(tableModel);
    JScrollPane scrollPane = new JScrollPane(table);
    Ashish

    Hi Ash
    I dont know whether this is feasible please sorry if i am wrong.
    Create a JPanel and add scroll bar to the left and top.
    I have posted a Q in the subject JDialog Esc Key. please answer the Q for me.
    Lakshmi.

  • JScrollPane: Can the Vertical Scroll Bar go on the left?

    Hope you can help,
    Im using a JScrollPane within another one, i.e, I have a component inside a JScrollPane, and one of its components is a JScrollPane. This is fine and dandy, but the internal scrolled component gets pretty tall and wide, so people end up using the OUTER horizontal scroll bar to scroll to the INNER vertical scrollbar to scroll DOWN the inner component.
    What would be really nice would be to have the INNER scrolled component to have its scroll bar on the LEFT to save the above hassle.
    Is this possible with JScrolledPane?

    In JScrollPane (jdk1.3)
    public void setComponentOrientation(ComponentOrientation co)
    Sets the orientation for the vertical and horizontal scrollbars as determined by the ComponentOrientation argument.
    Parameters:
    co - one of the following values:
    java.awt.ComponentOrientation.LEFT_TO_RIGHT
    java.awt.ComponentOrientation.RIGHT_TO_LEFT
    java.awt.ComponentOrientation.UNKNOWN

  • Keep vertical scroll bar still y JScrollPane

    Hello all!
    I have got a JTable added into a JScrollPane, which scroll bars are always shown.
    I have to repaint the JTable each 3 seconds and I would like to keep the vertical scroll bar in its original position, for example if I am watching row 24 of the JTable when the JTable is repainted I would like the vertical scroll bar to be in the same position as it was before repainting because now the vertical scroll bar is repainted always at the top...
    With the horizontal bar it works, the bar does not move from its previous state when the JTable is repainted...
    Any idea of what is happening?
    Thanks in advance :)

    This would do for u! ... do it after you have updated the table with the new rows... if you are not using the default table model then you can still get the row count through your JTable object ...
    This part moves the scrollbar to the last row coz im doing "myDefaultTableModel.getRowCount()-1", you can keep the current row index in an instance level variable bjust before refreshing the table and use it in this.setRowSelectionInterval() method ...
    this.setRowSelectionInterval(myDefaultTableModel.getRowCount()-1, myDefaultTableModel.getRowCount()-1);
    this.setColumnSelectionInterval(1, 1); //didnt need any specific column coz I wanted the row basically..
    this.scrollRectToVisible(this.getCellRect(this.getSelectedRow(), 1, true));This basically selects the given row and then moved the scrollbar over to that point as well ...
    OR, here's another alternative!! you can also get the current scrollbar value similarly jsut before refreshing and pass that on to this method ...
    this.jScrollPane1.getVerticalScrollBar().setValue(jScrollPane1.getVerticalScrollBar().getValue());Hope it helps...
    Cheers!
    Asim

  • JScrollPane's scroll bar alignment

    I tried all the suggested methods, and yet I still get the vertical scroll bar aligned somewhere in the middle when the JFrame opens, when top alignment would be preferable... Any suggestion on this is more than welcome. My code is structured with nested components like this:
    JScrollPane scroll
    ---JPanel allJPanels
    ------JPanel a
    ---------JPanel a_1
    ---------JLabel a_2
    ---------JEditorPane a_3
    ------JPanel b
    ---------JPanel b_1
    ---------JLabel b_2
    ---------JEditorPane b_3
    scroll.setViewportView( allJPanels );
    Methods attempted:
    scroll.getVerticalScrollBar().setValue( scroll.getVerticalScrollBar().getMinimum() );
    OR
    scroll.getViewport().setViewPosition( new java.awt.Point( 0, 0 ) );
    OR
    scroll.getVerticalScrollBar().getModel().setValue( 0 );     
    OR
    allJPanels.scrollRectToVisible( new java.awt.Rectangle( 1, 1, allJPanels.getWidth(), allJPanels.getHeight() ) );
    Thanks for any suggestion

    Could you please explain your exact requirement. If you just want whether you have to show the scrollpane or not then there is a policy in JScrollpane in which you can set the vertical scrollbar policy as required.

  • Double Scroll Bars, Side By Side, End To End, In A JScrollPane

    I'm trying to create double scroll bars next to each other, end to end. One scroll bar is for the position in the grid, while the other, smaller scroll bar controls the zoom level. I am masquerading a JPanel as a JScrollBar. I'm adding two scroll bars to the panel, and encapsulating the panel in a subclass of JScrollBar. You might wonder why I would do that. Because JScrollPane only accepts JScrollBar classes in setHorizontalScrollBar() and setVerticalScrollBar(). I tried to override every painting method I could think of that was important, but when I test it, nothing is shown. It is completely blank. Here is the code below. I know I still have to override the general JScrollBar methods and pass them to the primary scrollbar. Does anyone have any ideas on how to do somethink like I am attempting to do?
    import java.awt.*;
    import javax.swing.*;
    import java.lang.reflect.*;
    * <p>Title: </p>
    * <p>Description: This class masquerades as a JScrollBar, but it wraps two scrollbars next to each other. The
    * main scrollbar, and the secondary scrollbar which is smaller. Any calls which treat this as a regular scrollbar
    * will return the main scrollbar's values, while the special methods can be used to return the seondary scrollbar's
    * values.
    * </p>
    * <p>Copyright: Copyright (c) 2003</p>
    * <p>Company: </p>
    * @author not attributable
    * @version 1.0
    public class DoubleScrollBar extends JScrollBar {
      JPanel panel = new JPanel();
      JScrollBar primary;
      JScrollBar secondary;
      public DoubleScrollBar(int orientation) {
        init(orientation);
      void init() {
        panel.setLayout(new GridBagLayout());
        if ( orientation == JScrollBar.HORIZONTAL ) {
          primary = new JScrollBar(JScrollBar.HORIZONTAL);
          secondary = new JScrollBar(JScrollBar.HORIZONTAL);
          GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 0.75, 0.0,
              GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0);
          panel.add(primary, gbc);
          gbc.gridx = 1;
          gbc.weightx = 0.25;
          gbc.anchor = GridBagConstraints.EAST;
          panel.add(secondary, gbc);
        } else if ( orientation == JScrollBar.VERTICAL ) {
          primary = new JScrollBar(JScrollBar.VERTICAL);
          secondary = new JScrollBar(JScrollBar.VERTICAL);
          GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 0.0, 0.75,
              GridBagConstraints.NORTH, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0);
          panel.add(primary, gbc);
          gbc.gridy = 1;
          gbc.weighty = 0.25;
          gbc.anchor = GridBagConstraints.SOUTH;
          panel.add(secondary, gbc);
      public Dimension getPreferredSize() {
        return panel.getPreferredSize();
      public void setPreferredSize(Dimension d) {
        panel.setPreferredSize(d);
      public Dimension getSize() {
        return panel.getSize();
      public void paint(Graphics g) {
        panel.paint(g);
      public void paintAll(Graphics g) {
        panel.paintAll(g);
      protected void paintComponent(Graphics g) {
        try {
          Method m = panel.getClass().getMethod("paintComponent", new Class[] {Graphics.class});
          m.invoke(panel, new Object[] {g});
        catch (SecurityException ex) {
          System.out.println("SecurityException");
        catch (NoSuchMethodException ex) {
          System.out.println("NoSuchMethodException");
        catch (InvocationTargetException ex1) {
          System.out.println("InvocationTargetException");
        catch (IllegalArgumentException ex1) {
          System.out.println("IllegalArgumentException");
        catch (IllegalAccessException ex1) {
          System.out.println("IllegalAccessException");
      public void paintComponents(Graphics g) {
        panel.paintComponents(g);
      public void repaint(long tm, int x, int y, int w, int h) {
        if ( panel != null ) {
          panel.repaint(tm, x, y, w, h);
      public int getWidth() {
        return panel.getWidth();
      public int getHeight() {
        return panel.getHeight();
      public static void main(String[] args) {
        JFrame f = new JFrame();
        DoubleScrollBar dsb = new DoubleScrollBar(JScrollBar.HORIZONTAL);
        dsb.setPreferredSize(new Dimension(200, 50));
        f.getContentPane().add(dsb);
        f.pack();
        f.show();

    I know this isn't zooming, but maybe it will help.import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test3 extends JFrame {
      MyPanel mp = new MyPanel();
      public Test3() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        JScrollBar jsb = new JScrollBar();
        jsb.addAdjustmentListener(new AdjustmentListener() {
          public void adjustmentValueChanged(AdjustmentEvent ae) {
            mp.setSize(ae.getValue()*5);
        content.add(jsb, BorderLayout.EAST);
        mp.setPreferredSize(new Dimension(500,500));
        content.add(new JScrollPane(mp), BorderLayout.CENTER);
        setSize(300, 300);
      public static void main(String[] args) { new Test3().setVisible(true); }
    class MyPanel extends JPanel {
      int size;
      public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.red);
        g.drawRect(10,10,size,size);
      public void setSize(int size) {
        this.size=size;
        repaint();
    }

  • JList in JScrollPane never shows horizontal scroll bar

    I have a JList inside a JScrollPane. When I add a lot of cells to the list, the vertical scroll bar appears as expected. However, if I add a cell that would require lots of horizontal space in which to render, the horizontal scroll bar never appears.
    Is there a way to make the JList take on the width of the widest rendered cell?
    Josh

    Here's some code that will demonstrate the problem. Run the code, then resize the window so that the horizontal scroll bar should appear.
    Code for jds.toys.Main:
    package jds.toys;
    import javax.swing.DefaultListModel;
    import javax.swing.JFrame;
    import javax.swing.JList;
    import javax.swing.JScrollPane;
    import javax.swing.SwingUtilities;
    public class Main extends JFrame {
         protected DefaultListModel model;
         public Main()
              super("JList in JScrollPane");
              model = new DefaultListModel();
              model.addElement("A very very very very very very long String");
              model.addElement("A very very very very very very very long String");
              model.addElement("A very very very very very very very very long String");
              model.addElement("A very very very very very very very very very long String");
              model.addElement("A very very very very very very very very very very long String");
              model.addElement("A very very very very very very very very very very very long String");
                      JList list = new JList(model);
                      list.setSize(300,300);
                      list.setFixedCellHeight(30);
                      list.setCellRenderer(new MyCellRenderer());
                      JScrollPane scrollPane = new JScrollPane(list);
                      add(scrollPane);
                      setSize(400,400);
        public static void main(String[] args) throws InterruptedException {
             final Main m = new Main();
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                     m.setVisible(true);
    Code for jds.toys.MyCellRenderer:
    package jds.toys;
    import java.awt.Component;
    import java.awt.Graphics;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.ListCellRenderer;
    public class MyCellRenderer extends JPanel implements ListCellRenderer
         private Object currentValue;
         private JList currentList;
         public MyCellRenderer()
         public Component getListCellRendererComponent(     JList list,
                                             Object value,
                                       int index,
                                       boolean isSelected,
                                       boolean cellHasFocus)
              currentValue = value;
              currentList = list;
              return this;
         public void paintComponent(Graphics g)
              int stringLen = g.getFontMetrics().stringWidth(currentValue.toString());
              int ht = currentList.getFixedCellHeight();
              g.setColor(getBackground());
              g.fillRect(0,0,stringLen,ht);
              g.setColor(getForeground());
              g.drawString(currentValue.toString(),0,ht/2);
    }

  • JScrollPane - change vertical scroll-bar

    I am developing an application to be run on a touch-screen monitor. The customer has asked that I make the vertical scroll-bar on the tables easier to use. How do I set the width of the scroll-bar(s) in a JScrollPane?

    Do you want to set the width of all vertical scroll bars (and in that case, probably also the height of all horizontal scroll bars too) OR the width of one specific scroll bar of one specific scroll pane?
    db

  • Nested JScrollPanes: who gets a scroll bar ?

    I have a JFrame that contains a JScrollPane (A) taht contains a JTabbedPane that contains a JScrollPane (B) that contains a JTable. When I resize the window, I get scrollbars. But I can't control where. I would like scroll bars to appear on the root JScrollPane (A) only as a "last resort" when there is no other way to represent the JTabbedane (for example if it has hundreds of tabs). The rest of the time, I would like to have scrollbars only for the JTable (B).
    Here is a code example:
    package test;
    import java.awt.BorderLayout;
    import javax.swing.*;
    import javax.swing.table.*;
    public class NestedScrollpanes extends JFrame {
        private static final long serialVersionUID = 1L;
        private TableModel getTableModel() {
            return new DefaultTableModel(new Object[] {
                    "A", "B", "C", "D", "E",
                    "F", "G", "H", "I", "J",
                    "K", "L", "M", "N", "O"}, 100);
        public NestedScrollpanes() {
            super("Test");
            JPanel rootPanel = new JPanel(new BorderLayout());
            JTabbedPane tabbedPane = new JTabbedPane();
            JScrollPane rootScrollPane = new JScrollPane(tabbedPane); // A
            JTable table = new JTable(getTableModel());
            JScrollPane tableScrollPane = new JScrollPane(table); // B
            getContentPane().add(rootPanel, BorderLayout.CENTER);
            rootPanel.add(rootScrollPane);
            tabbedPane.addTab("TAB", tableScrollPane);
            setSize(100, 100);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
        public static void main(String[] args) {
            new NestedScrollpanes();
    }Any idea ?

    How's this:
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Rectangle;
    import javax.swing.*;
    import javax.swing.table.*;
    public class NestedScrollpanes extends JFrame {
        private static final long serialVersionUID = 1;
        private TableModel getTableModel() {
            return new DefaultTableModel(new Object[] {
                    "A", "B", "C", "D", "E",
                    "F", "G", "H", "I", "J",
                    "K", "L", "M", "N", "O"}, 100);
        public NestedScrollpanes() {
            super("Test");
            JPanel rootPanel = new JPanel(new BorderLayout());
            JTabbedPane tabbedPane = new OptionalScrollTabbedPane();
            JScrollPane rootScrollPane = new JScrollPane(tabbedPane); // A
            JTable table = new JTable(getTableModel());
            JScrollPane tableScrollPane = new JScrollPane(table); // B
            JPanel panel = new JPanel();
            panel.setLayout( new BoxLayout( panel, BoxLayout.Y_AXIS ) );
            for ( int k = 0 ; k < 50 ; k++ )
                 panel.add( new JTextField() );
            getContentPane().add(rootPanel, BorderLayout.CENTER);
            rootPanel.add(rootScrollPane);
            tabbedPane.addTab("ScrollPane", tableScrollPane);
            tabbedPane.addTab( "TextFields", panel );
            setSize(200, 200);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
        public static void main(String[] args) {
            new NestedScrollpanes();
        public static class OptionalScrollTabbedPane extends JTabbedPane implements Scrollable {
             private int unitIncrement = new JTextField().getPreferredSize().height;
              public Dimension getPreferredScrollableViewportSize() {
                   return getPreferredSize();
              public int getScrollableBlockIncrement( Rectangle visibleRect, int orientation, int direction ) {
                   int block;
                   JViewport view = (JViewport) SwingUtilities.getAncestorOfClass( JViewport.class, this );
                   if ( view != null )
                        block = orientation == SwingConstants.VERTICAL ? view.getHeight() : view.getWidth();
                   else // arbitrarily set block size to one-tenth the dimension
                        block = ( orientation == SwingConstants.VERTICAL ? getHeight() : getWidth() ) / 10;
                   return block;
              public boolean getScrollableTracksViewportHeight() {
                   boolean rv = false;
                   int index = getSelectedIndex();
                   if ( index != -1 ) {
                        rv = ( getComponentAt( index ) instanceof JScrollPane );
                   return rv;
              public boolean getScrollableTracksViewportWidth() {
                   boolean rv = false;
                   int index = getSelectedIndex();
                   if ( index != -1 ) {
                        rv = ( getComponentAt( index ) instanceof JScrollPane );
                   return rv;
              public int getScrollableUnitIncrement( Rectangle visibleRect, int orientation, int direction ) {
                   return unitIncrement;
    }

Maybe you are looking for