-1

I am trying to design a class of endless coordinate board with a grid. I have extended a JViewport and it draws at initial position ok (inside JScrollPane). How to tell scroll pane that there are some space to scroll in any direction?

The following does not help

            JCoordinateViewport coordinate = new JCoordinateViewport();
            coordinate.setBackground(Color.WHITE);
            //coordinate.setPreferredSize(new Dimension(10000, 10000));

            JScrollPane scroll = new JScrollPane();
            //scroll.setViewportView(coordinate);
            scroll.setViewport(coordinate);
            scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
            scroll.getVerticalScrollBar().setMinimum(-10000);
            scroll.getVerticalScrollBar().setMaximum(+10000);
            scroll.getHorizontalScrollBar().setMinimum(-10000);
            scroll.getHorizontalScrollBar().setMaximum(+10000);

UPDATE

Does anybody knows how JScrollPane determines scroll ranges from it's viewport?

UPDATE2

I found, that scrollbars appear t work if maximums and minimums are set after setVisible called.

But unfortunately, paintConponent does not called upon scroll.

Why?

UPDATE3

Although scroll bars work, they don't change viewport position.

Why?

4

2 回答 2

2

如此处所示在 a 上绘画JViewport似乎“粘”在视口上,而在底层可滚动组件上绘画则滑到下方。尺寸是 的整数倍TILE:出于演示目的,视口的首选尺寸小于底层面板;在实践中,最好覆盖getPreferredSize(). 另请参阅 ScrollAction,当鼠标悬停在任何边框附近时,它会自动滚动。

图片

于 2013-02-22T02:53:40.577 回答
2
CoordinateViewport coordinate = new JCoordinateViewport(); coordinate.setBackground(Color.WHITE); //coordinate.setPreferredSize(new Dimension(10000, 10000));

JScrollPane scroll = new JScrollPane(); //scroll.setViewportView(coordinate);
scroll.setViewport(coordinate); 
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); 
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); 
scroll.getVerticalScrollBar().setMinimum(-10000); 
scroll.getVerticalScrollBar().setMaximum(+10000); 
scroll.getHorizontalScrollBar().setMinimum(-10000); 
scroll.getHorizontalScrollBar().setMaximum(+10000);

.

以下没有帮助

  • 那么问题应该只在有名字的类中CoordinateViewport

  • 为了获得更好的帮助,请尽快发布SSCCE,简短,可运行,可编译,差不多JFrameJScrollPaneJViewport

  • 为了减少闪烁,JViewport需要设置

    1. 自己的RepaintManager

    2. 并通过使用/使用内置方法JViewport

    JViewport.setScrollMode(JViewport.BLIT_SCROLL_MODE); JViewport.setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE); JViewport.setScrollMode(JViewport.SIMPLE_SCROLL_MODE);

  • 请参阅传递当前日期JTable 如何将背景颜色更改为SSCCE的潜在来源

于 2013-02-21T21:59:42.517 回答