更新:第二个解决方案非常有效,但您必须小心某些对象的大小,以使ScrollBar的默认值不处于活动状态。您不能同时隐藏两者,您必须做出选择;)
我想隐藏滚动条,但仍然可以在我的JScrollPane上滚动。我试过这个:
scrollPane.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_NEVER);
但我不能再滚动了:(我也尝试过这个:
scrollPane.getVerticalScrollBar().setPreferredSize (new Dimension(0,0));
scrollPane.getHorizontalScrollBar().setPreferredSize (new Dimension(0,0));
scrollPane.getVerticalScrollBar().setMinimumSize(new Dimension(0, 0));
scrollPane.getVerticalScrollBar().setMinimumSize(new Dimension(0, 0));
scrollPane.getVerticalScrollBar().setMaximumSize(new Dimension(0, 0));
scrollPane.getVerticalScrollBar().setMaximumSize(new Dimension(0, 0));
但当我滚动时,仍然可以看到滚动条的1个像素(我认为默认情况下):(
我找到了解决方案:
panLeft.setBackground(new Color(1, 0, 0, 0));
panLeft.setLayout(null);
panLeft.setPreferredSize(null);
panLeft.addMouseWheelListener(new MouseWheelListenerPanLeft());
scrollPaneLeft.setBounds(10, 35, 250, 525);
scrollPaneLeft.setBackground(new Color(1, 0, 0, 0));
scrollPaneLeft.getVerticalScrollBar().setPreferredSize(new Dimension(0, 0));
scrollPaneLeft.getViewport().setBorder(null);
scrollPaneLeft.setViewportBorder(null);
scrollPaneLeft.setBorder(null);