开发者

Scroll problem - doesn't scroll when I press

I have strange problem in Java. I have JScrollPane

paneScroll=new JScrollPane(nav,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

where nav is JPanel

public class ScrollableNavigationPanelZones extends JPanel {
    private ButtonGroup buttonGroup = new ButtonGroup();
    private static final long serialVersionUID = -455651438039139284L;
    protected JViewport viewport;
    private JPanel panel;

    private int offset = 100;

    public ScrollableNavigationPanelZones() {
        super();
        setLayout(new BorderLayout());

        panel = new JPanel();
        panel.setPreferredSize(new Dimension(0,160));
        FlowLayout fl = new FlowLayout();
        fl.setVgap(5);
        fl.setAlignment(FlowLayout.LEFT);
        panel.setLayout(fl);
        add(panel,BorderLayout.CENTER);



    }
    }

and it shows scroll on right side but doesn't have that small box which to move ( I have arrows on top and bottom of scroll, but when I press I cannot scroll ). When I change in ScrollableNavigationPane开发者_如何学JAVAlZones panel.setPreferredSize(new Dimension(0,16000)); it works but shows empty space. Why JScrollPane doesn't read real height of panel ? What is mistake ? Can anybody help please ?


The scroll box is displayed only if there is something to scroll, i.e. if the preferred height of the panel exceeds the actual height of the scroll pane. Of course, if you set the preferred height to 16000 it will show much of empty space if the panel doesn't fill all the 16000 pixels with controls.

If the panel fits in the scroll pane, the scroll bar is by default hidden. The flag VERTICAL_SCROLLBAR_ALWAYS implies that the scroll bar is visible always, even if not needed. If you set the panel height to 160 pixels and the scroll pane is larger, you see the scroll bar (because it's ALWAYS) but no scroll box (because there is actually nothing to scroll).

It's a bit strange that the up and down buttons on the scroll bar are clickable even if there is nothing to scroll. Usually they should be greyed out in this case. Maybe there is some additional parameter in JScrollPane for this...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜