public void mouseWheelMoved(MouseWheelEvent e) { int notches = e.getWheelRotation(); int sign = 1; if (notches > 0) { sign = -1; } if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { int numClicks = e.getScrollAmount(); scale = scale + (numClicks * 0.1f) * sign; if (scale <= 0) scale = 0.1f; } TheDisplayPanel.initDisplay(); TheDisplayPanel.repaint(); JScrollBar verticalScrollBar = TheScrollPane.getVerticalScrollBar(); JScrollBar horizScrollBar = TheScrollPane.getHorizontalScrollBar(); // Point pInImage = new // Point((int)(mouseMovePoint.x+lastScrollValueX), // (int)(mouseMovePoint.y+lastScrollValueY)); verticalScrollBar.setValue((int) (lastScrollValueY + mouseMovePoint.y)); horizScrollBar.setValue((int) (lastScrollValueX + mouseMovePoint.x)); lastScrollValueX = horizScrollBar.getValue(); lastScrollValueY = verticalScrollBar.getValue(); TheFrame.validate(); TheFrame.repaint(); }
public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub Dragging = true; startPoint = e.getPoint(); JScrollBar verticalScrollBar = TheScrollPane.getVerticalScrollBar(); JScrollBar horizScrollBar = TheScrollPane.getHorizontalScrollBar(); lastScrollValueX = horizScrollBar.getValue(); lastScrollValueY = verticalScrollBar.getValue(); }
public void mouseDragged(MouseEvent e) { JScrollBar verticalScrollBar = TheScrollPane.getVerticalScrollBar(); JScrollBar horizScrollBar = TheScrollPane.getHorizontalScrollBar(); verticalScrollBar.setValue((int) (lastScrollValueY + startPoint.y - e.getPoint().y)); horizScrollBar.setValue((int) (lastScrollValueX + startPoint.x - e.getPoint().x)); lastScrollValueX = horizScrollBar.getValue(); lastScrollValueY = verticalScrollBar.getValue(); }