更新:第二个解决方案完美运行,但您必须小心某些对象的大小,以免 ScrollBar 的默认值处于 Activity 状态。您不能同时隐藏两者,您必须做出选择;)
我想隐藏 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));
但是当我滚动时仍然可以看到 ScrollBar 的 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);
关于java - 在 JScrollPane 中隐藏 JScrollBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17551921/