List of usage examples for java.awt.event MouseWheelEvent getWheelRotation
public int getWheelRotation()
From source file:Main.java
/** * Creates a JSlider built//from w ww . ja v a 2s. c o m * using a {@link DefaultBoundedRangeModel} and * containing a {@link MouseWheelListener} * and some usual default settings * * @param model * @return the corresponding {@link JSlider} */ public static JSlider createJSlider(final BoundedRangeModel model) { final JSlider slider = new JSlider(model); slider.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { slider.setValue(-e.getWheelRotation() * model.getMaximum() / 100 + model.getValue()); } }); slider.setPaintTicks(true); slider.setPaintLabels(true); // slider.setMajorTickSpacing(model.getMaximum()/2); // slider.setMinorTickSpacing(model.getMaximum()/10); // slider.setSnapToTicks(true); return slider; }
From source file:Main.java
public static MouseEvent convertMouseEvent(Component source, MouseEvent sourceEvent, Component destination) { Point p = SwingUtilities.convertPoint(source, new Point(sourceEvent.getX(), sourceEvent.getY()), destination);/*from www . j a v a2 s . c o m*/ Component newSource; if (destination != null) newSource = destination; else newSource = source; MouseEvent newEvent; if (sourceEvent instanceof MouseWheelEvent) { MouseWheelEvent sourceWheelEvent = (MouseWheelEvent) sourceEvent; newEvent = new MouseWheelEvent(newSource, sourceWheelEvent.getID(), sourceWheelEvent.getWhen(), sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y, sourceWheelEvent.getClickCount(), sourceWheelEvent.isPopupTrigger(), sourceWheelEvent.getScrollType(), sourceWheelEvent.getScrollAmount(), sourceWheelEvent.getWheelRotation()); } else if (sourceEvent instanceof MenuDragMouseEvent) { MenuDragMouseEvent sourceMenuDragEvent = (MenuDragMouseEvent) sourceEvent; newEvent = new MenuDragMouseEvent(newSource, sourceMenuDragEvent.getID(), sourceMenuDragEvent.getWhen(), sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y, sourceMenuDragEvent.getClickCount(), sourceMenuDragEvent.isPopupTrigger(), sourceMenuDragEvent.getPath(), sourceMenuDragEvent.getMenuSelectionManager()); } else { newEvent = new MouseEvent(newSource, sourceEvent.getID(), sourceEvent.getWhen(), sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y, sourceEvent.getClickCount(), sourceEvent.isPopupTrigger(), sourceEvent.getButton()); } return newEvent; }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(200, 200);/* w w w. ja v a2s . c o m*/ JTextArea textArea = new JTextArea(); textArea.addMouseWheelListener(new MouseWheelListener() { public void mouseWheelMoved(MouseWheelEvent e) { if (e.getWheelRotation() < 0) { System.out.println("Up... " + e.getWheelRotation()); } else { System.out.println("Down... " + e.getWheelRotation()); } System.out.println("ScrollAmount: " + e.getScrollAmount()); if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { System.out.println("MouseWheelEvent.WHEEL_UNIT_SCROLL"); } if (e.getScrollType() == MouseWheelEvent.WHEEL_BLOCK_SCROLL) { System.out.println("MouseWheelEvent.WHEEL_BLOCK_SCROLL"); } } }); getContentPane().add(textArea); }
From source file:MouseWheelTest.java
public MouseWheelTest() { super();/*w w w .ja va2 s. co m*/ final Container contentPane = getContentPane(); MouseWheelListener listener = new MouseWheelListener() { int colorCounter; private static final int UP = 1; private static final int DOWN = 2; public void mouseWheelMoved(MouseWheelEvent e) { int count = e.getWheelRotation(); int direction = (Math.abs(count) > 0) ? UP : DOWN; changeBackground(direction); } private void changeBackground(int direction) { contentPane.setBackground(colors[colorCounter]); if (direction == UP) { colorCounter++; } else { --colorCounter; } if (colorCounter == colors.length) { colorCounter = 0; } else if (colorCounter < 0) { colorCounter = colors.length - 1; } } }; contentPane.addMouseWheelListener(listener); }
From source file:Main.java
public void mouseWheelMoved(MouseWheelEvent e) { String message;//from w w w . ja va 2s . co m int notches = e.getWheelRotation(); if (notches < 0) { message = "Mouse wheel moved UP " + -notches + " notch(es)" + newline; } else { message = "Mouse wheel moved DOWN " + notches + " notch(es)" + newline; } if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { message += " Scroll type: WHEEL_UNIT_SCROLL" + newline; message += " Scroll amount: " + e.getScrollAmount() + " unit increments per notch" + newline; message += " Units to scroll: " + e.getUnitsToScroll() + " unit increments" + newline; message += " Vertical unit increment: " + scrollPane.getVerticalScrollBar().getUnitIncrement(1) + " pixels" + newline; } else { // scroll type == MouseWheelEvent.WHEEL_BLOCK_SCROLL message += " Scroll type: WHEEL_BLOCK_SCROLL" + newline; message += " Vertical block increment: " + scrollPane.getVerticalScrollBar().getBlockIncrement(1) + " pixels" + newline; } saySomething(message, e); }
From source file:Test.java
public void mouseWheelMoved(MouseWheelEvent e) { System.out.println("" + e.getPreciseWheelRotation() + " - " + e.getWheelRotation()); }
From source file:MouseWheelEventDemo.java
public void mouseWheelMoved(MouseWheelEvent e) { String message;/*w w w. ja v a 2s . com*/ int notches = e.getWheelRotation(); if (notches < 0) { message = "Mouse wheel moved UP " + -notches + " notch(es)" + newline; } else { message = "Mouse wheel moved DOWN " + notches + " notch(es)" + newline; } if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { message += " Scroll type: WHEEL_UNIT_SCROLL" + newline; message += " Scroll amount: " + e.getScrollAmount() + " unit increments per notch" + newline; message += " Units to scroll: " + e.getUnitsToScroll() + " unit increments" + newline; message += " Vertical unit increment: " + scrollPane.getVerticalScrollBar().getUnitIncrement(1) + " pixels" + newline; } else { //scroll type == MouseWheelEvent.WHEEL_BLOCK_SCROLL message += " Scroll type: WHEEL_BLOCK_SCROLL" + newline; message += " Vertical block increment: " + scrollPane.getVerticalScrollBar().getBlockIncrement(1) + " pixels" + newline; } saySomething(message, e); }
From source file:events.MouseWheelEventDemo.java
public void mouseWheelMoved(MouseWheelEvent e) { String message;/*from w ww. ja v a2 s.co m*/ int notches = e.getWheelRotation(); if (notches < 0) { message = "Mouse wheel moved UP " + -notches + " notch(es)" + NEWLINE; } else { message = "Mouse wheel moved DOWN " + notches + " notch(es)" + NEWLINE; } if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { message += " Scroll type: WHEEL_UNIT_SCROLL" + NEWLINE; message += " Scroll amount: " + e.getScrollAmount() + " unit increments per notch" + NEWLINE; message += " Units to scroll: " + e.getUnitsToScroll() + " unit increments" + NEWLINE; message += " Vertical unit increment: " + scrollPane.getVerticalScrollBar().getUnitIncrement(1) + " pixels" + NEWLINE; } else { //scroll type == MouseWheelEvent.WHEEL_BLOCK_SCROLL message += " Scroll type: WHEEL_BLOCK_SCROLL" + NEWLINE; message += " Vertical block increment: " + scrollPane.getVerticalScrollBar().getBlockIncrement(1) + " pixels" + NEWLINE; } eventOutput(message, e); }
From source file:com.vgi.mafscaling.MafChartPanel.java
public void mouseWheelMoved(MouseWheelEvent e) { if (e.getScrollType() != MouseWheelEvent.WHEEL_UNIT_SCROLL) return;//from www .j a va 2s . co m if (e.getWheelRotation() < 0) zoomChartAxis(chartPanel, true); else zoomChartAxis(chartPanel, false); }
From source file:playground.sergioo.capacitiesChanger2012.gui.NetworkPanel.java
@Override public void mouseWheelMoved(MouseWheelEvent e) { if (e.getWheelRotation() < 0) camera.zoomIn();//from w ww . j ava 2 s . co m else if (e.getWheelRotation() > 0) camera.zoomOut(); repaint(); }