Refine search
setLayout(new ScrollPopupMenuLayout()); addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent event) { JScrollBar scrollBar = getScrollBar(); int amount = (event.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) ? event.getUnitsToScroll() * scrollBar.getUnitIncrement() : (event.getWheelRotation() < 0 ? -1 : 1) * scrollBar.getBlockIncrement(); popupScrollBar.addAdjustmentListener(new AdjustmentListener() { @Override public void adjustmentValueChanged(AdjustmentEvent e) { doLayout(); repaint(); super.addImpl(comp, constraints, index); if(maximumVisibleRows < getComponentCount()-1) { getScrollBar().setVisible(true); if(scrollBar.isVisible()){ int extent = 0; int max = 0;
@Override public void mouseWheelMoved(MouseWheelEvent e) { if (e.getWheelRotation() == 0) { if ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0) { Font font = textArea.getFont(); int size = font.getSize(); if (e.getWheelRotation() > 0) { textArea.setFont(new Font(font.getName(), font.getStyle(), --size >= 8 ? --size : 8)); } else { if (scrollPane.isWheelScrollingEnabled() && e.getWheelRotation() != 0) { JScrollBar toScroll = scrollPane.getVerticalScrollBar(); int direction = e.getWheelRotation() < 0 ? -1 : 1; int orientation = SwingConstants.VERTICAL; if (toScroll == null || !toScroll.isVisible()) { e.consume(); if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { JViewport vp = scrollPane.getViewport(); if (vp == null) { int units = Math.abs(e.getUnitsToScroll()); boolean limitScroll = Math.abs(e.getWheelRotation()) == 1; Object fastWheelScroll = toScroll.getClientProperty("JScrollBar.fastWheelScrolling"); if (Boolean.TRUE == fastWheelScroll && comp instanceof Scrollable) { } else if (e.getScrollType() == MouseWheelEvent.WHEEL_BLOCK_SCROLL) { int oldValue = toScroll.getValue();
private MouseWheelEvent translateEvent(MouseWheelEvent e) { Dimension stretchedDimensions = client.getStretchedDimensions(); Dimension realDimensions = client.getRealDimensions(); int newX = (int) (e.getX() / (stretchedDimensions.width / realDimensions.getWidth())); int newY = (int) (e.getY() / (stretchedDimensions.height / realDimensions.getHeight())); return new MouseWheelEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), newX, newY, e.getClickCount(), e.isPopupTrigger(), e.getScrollType(), e.getScrollAmount(), e.getWheelRotation()); } }
public void mouseWheelMoved(MouseWheelEvent e) { double f = e.getWheelRotation() * 0.2; zoom(f, e.getPoint()); }
public void handleWheel(final MouseWheelEvent event) { if (parent == null || !canvasBounds.contains(event.getPoint())) { return; } event.consume(); clientThread.invoke(() -> { if (isHidden()) { return; } scrollTab(event.getWheelRotation()); }); }
JFrame jf = new JFrame("test"); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setSize(800, 800); containerPanel.setLayout(new GridBagLayout()); containerPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(1, 0, 1))); containerPanel.add(zoomPanel); zoomPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); jf.add(new JScrollPane(containerPanel)); jf.setVisible(true); addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { updatePreferredSize(e.getWheelRotation(), e.getPoint()); getParent().setLocation(getParent().getLocation().x-offX,getParent().getLocation().y-offY);
setLayout(new BorderLayout()); mouseWheelListener = createMouseWheelListener(); tipArea = new JTextArea(rows, columns); JComponent component = getComponent(); if (component != null) { tipArea.dispatchEvent(new MouseWheelEvent(tipArea, e.getID(), e.getWhen(), e.getModifiers(), 0, 0, e.getClickCount(), e.isPopupTrigger(), e.getScrollType(), e.getScrollAmount(), e.getWheelRotation())); JComponent component = getComponent(); if (component != null) { component.addMouseWheelListener(mouseWheelListener); JComponent component = getComponent(); if (component != null) { component.removeMouseWheelListener(mouseWheelListener); return getComponent(0).getPreferredSize(); e.printStackTrace(); f.add(new JScrollPane(table)); f.setVisible(true);
try { ImageZoom window = new ImageZoom(); window.frmImageZoomIn.setVisible(true); } catch (Exception e) { e.printStackTrace(); frmImageZoomIn = new JFrame(); frmImageZoomIn.setTitle("Image Zoom In and Zoom Out"); frmImageZoomIn.setBounds(100, 100, 450, 300); frmImageZoomIn.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JScrollPane scrollPane = new JScrollPane(); frmImageZoomIn.getContentPane().add(scrollPane, BorderLayout.CENTER); panel.setLayout(new BorderLayout()); panel.add(label, BorderLayout.CENTER); panel.addMouseWheelListener(new MouseWheelListener() { public void mouseWheelMoved(MouseWheelEvent e) { int notches = e.getWheelRotation(); double temp = zoom - (notches * 0.2); scrollPane.setViewportView(panel);
JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().setLayout(new GridLayout(1,2)); JScrollPane scrollPane = new JScrollPane(m); f.getContentPane().add(scrollPane); f.setSize(500,500); f.setLocationRelativeTo(null); f.setVisible(true); addMouseWheelListener(this); if (e.getWheelRotation() < 0) getParent().dispatchEvent(e);
doc.insertString(doc.getLength(), "\n", null); doc.insertString(doc.getLength(), TEXT, null); textPane.insertComponent(new JScrollPane(tree)); doc.insertString(doc.getLength(), "\n", null); doc.insertString(doc.getLength(), TEXT, null); new JScrollPane(textPane), new WheelScrollLayerUI()); MouseWheelEvent e, JLayer<? extends JScrollPane> l) { Component c = e.getComponent(); int dir = e.getWheelRotation(); JScrollPane main = l.getView(); if (c instanceof JScrollPane && !c.equals(main)) { JScrollPane child = (JScrollPane) c; BoundedRangeModel m = child.getVerticalScrollBar().getModel(); int extent = m.getExtent(); int minimum = m.getMinimum(); int value = m.getValue(); if (value + extent >= maximum && dir > 0 || value <= minimum && dir < 0) { main.dispatchEvent(SwingUtilities.convertMouseEvent(c, e, main));
JFrame frame = new JFrame("MouseWheelEventDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(newContentPane); frame.pack(); frame.setVisible(true); textArea.addMouseWheelListener(this); int notches = e.getWheelRotation(); if (notches < 0) { message = "Mouse wheel moved UP " + 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
JFrame frame = new JFrame(); frame.setLayout(new BorderLayout()); frame.add(new ScrollPanePanel()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400); frame.setVisible(true); panel.add(new JLabel("Label " + i)); panel.addMouseWheelListener(this); scrollPane = new JScrollPane(panel); infoPanel.add(infoLabel); setLayout(new BorderLayout()); public void mouseWheelMoved(MouseWheelEvent e) { if (e.isControlDown()) { if (e.getWheelRotation() < 0) { infoLabel.setText("Mouse Wheel Up"); } else {
int rotation = e.getWheelRotation(); if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) JScrollBar vertical = scrollPane.getVerticalScrollBar(); int unitsToScroll = Math.abs( e.getUnitsToScroll() ); list.setVisibleRowCount(20); JScrollPane scrollPane = new JScrollPane(list, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.addMouseWheelListener( new MouseWheelScroller()); JFrame frame = new JFrame("Mouse Wheel Scroller"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add( scrollPane ); frame.pack(); frame.setLocationByPlatform( true ); frame.setVisible( true );
JScrollPane scrollPane = new JScrollPane(textArea); add(scrollPane, BorderLayout.CENTER); textArea.addMouseWheelListener(this); if (e.getWheelRotation() < 0) { JComponent component = (JComponent)e.getComponent(); Action action = component.getActionMap().get(SOME_ACTION); JFrame frame = new JFrame("MouseWheelTest"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add( new MouseWheelTest() ); frame.pack(); frame.setLocationRelativeTo( null ); frame.setVisible(true);
JFrame jf = new JFrame("test"); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setSize(400, 400); addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { updatePreferredSize(e.getWheelRotation(), e.getPoint()); getParent().setLocation(getParent().getLocation().x-offX,getParent().getLocation().y-offY); getParent().doLayout(); // do the layout for containerPanel getParent().getParent().doLayout(); // do the layout for jf (JFrame)
import javax.swing.*; import java.awt.event.*; public class TestSpinner extends JFrame implements MouseWheelListener { public TestSpinner() { setSize( 100, 50 ); spinner = new JSpinner(); spinner.addMouseWheelListener( this ); getContentPane().add( spinner, "Center" ); } public void mouseWheelMoved( MouseWheelEvent e ) { spinner.setValue( new Integer( ((Integer)spinner.getValue()).intValue() - e.getWheelRotation() ) ); } public static void main( String [] args ) { TestSpinner t = new TestSpinner(); t.setVisible( true ); } private JSpinner spinner; }
b.addMouseMotionListener(behavior); b.addMouseListener(behavior); b.addMouseWheelListener(behavior); JFrame f = new JFrame(); f.setLocation(10, 10); f.setDefaultCloseOperation(3); f.add(b); f.pack(); f.setVisible(true); zoom = Math.min(2000, Math.max(0, zoom + e.getUnitsToScroll() * 10)); if (e.getSource() instanceof JComponent) { ((JComponent) e.getSource()).repaint();
JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new TestPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); addMouseWheelListener(new MouseWheelListener() { int rotation = e.getWheelRotation(); if (rotation < 0) { scale -= scaleDelta; scale = 1; repaint();
if (e.getWheelRotation() < 0 && map.getZoom() >= getMaxZoomLevel()) return; super.mouseWheelMoved(e); JFrame frame = new JFrame("Demo"); JMapViewer viewer = new JMapViewer(new MemoryTileCache(), 8); new CustomMapController(viewer); frame.add(viewer); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationByPlatform(true); frame.pack(); frame.setVisible(true);
setSize(300, 300); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); addComponentsToContentPane(getContentPane()); addListeners(); setVisible(true); contentPane.add(jspinner); this.addMouseWheelListener(new MouseWheelListener() { if (MouseWheelEvent.WHEEL_UNIT_SCROLL == mwe.getScrollType()) { int value = (int) jspinner.getValue(); if (mwe.getWheelRotation() == -1) {//up jspinner.setValue(value + 1); } else {//down