我正在尝试隐藏滚动窗格的垂直条,但我希望它继续垂直滚动。这是我的代码:
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);
对我来说这很好,如果它只显示箭头。所以这就是我需要的:
答案 0 :(得分: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以了解其工作原理。