0

I'm trying to hide the vertical bar of a scrollpane, but I want that it continues scrolling vertically. This is my code:

JScrollPane scroll=new JScrollPane(arbol);
        scroll.setBounds(35,40, 230, 530);
        scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        scroll.setBorder(null);
        scroll.setOpaque(false);
        scroll.getVerticalScrollBar().setBorder(null);
        scroll.getViewport().setOpaque(false);
        JLabel sep=new JLabel(Imagen("SeparaV.png"));
        sep.setSize(scroll.getSize());
        sep.setLocation(-17, 0);
        sep.setHorizontalAlignment(JLabel.RIGHT);
        scroll.add(sep);
        Frame.add(scroll);

For me it is good, if it only shows the arrows. So this is what I need:

enter image description here

4

1 回答 1

0

对我来说,只要显示箭头就好了

我假设您的意思是您不想在中间看到用于拖动滚动条的栏。如果是这样,那么您可以使用滚动条的默认操作来创建一个只有箭头按钮的简单面板:

在此处输入图像描述

import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.basic.*;

public class ScrollPaneSSCCE extends JPanel
{
    public ScrollPaneSSCCE()
    {
        setLayout( new BorderLayout() );
        JTable table = new JTable(50, 5);
        JScrollPane scrollPane = new JScrollPane( table );
        scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
        add(scrollPane);
        JScrollBar vertical = scrollPane.getVerticalScrollBar();

        JPanel east = new JPanel( new BorderLayout() );
        add(east, BorderLayout.EAST);

        BasicArrowButton north = new BasicArrowButton(BasicArrowButton.NORTH);
        north.setAction( new ActionMapAction("", vertical, "negativeUnitIncrement") );
        east.add(north, BorderLayout.NORTH);

        BasicArrowButton south = new BasicArrowButton(BasicArrowButton.SOUTH);
        south.setAction( new ActionMapAction("", vertical, "positiveUnitIncrement") );
        east.add(south, BorderLayout.SOUTH);
    }

    private static void createAndShowUI()
    {
        JFrame frame = new JFrame("ScrollPaneSSCCE");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.add(new ScrollPaneSSCCE());
        frame.setSize(200, 300);
        frame.setLocationByPlatform( true );
        frame.setVisible( true );
    }

    public static void main(String[] args)
    {
        EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                createAndShowUI();
            }
        });
    }
}

您需要查看Action Map Action以了解其工作原理。

于 2013-10-10T15:47:08.640 回答