e821. 设置JScrollPane滚动栏

A scroll bar in a scroll pane can be set to appear only as needed, always appear, or never appear. By default, both the vertical and horizontal scrollbars in a scroll pane appear only when needed.

    // Create a scrollable text area
    JTextArea textArea = new JTextArea();
    JScrollPane pane = new JScrollPane(textArea);
    
    // Get the default scrollbar policy
    int hpolicy = pane.getHorizontalScrollBarPolicy();
    // JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED;
    
    int vpolicy = pane.getVerticalScrollBarPolicy();
    // JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED;
    
    
    // Make the scrollbars always appear
    pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    
    // Make the scrollbars never appear
    pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);

 

Related Examples
posted @ 2018-09-06 09:02  borter  阅读(364)  评论(0编辑  收藏  举报