Java 8 JViewport - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 JViewport class.

This code example shows how to use the following methods:getExtentSize, getViewPosition, setViewPosition
    public void autoscroll(Point cursorLoc) {
        JViewport viewport = getViewport();
        if (viewport == null) {
            return; 
        } 
        Point viewPos = viewport.getViewPosition();
        int viewHeight = viewport.getExtentSize().height;
        int viewWidth = viewport.getExtentSize().width;
 
        // resolve scrolling 
        if ((cursorLoc.y - viewPos.y) < insets.top) { // scroll up
            viewport.setViewPosition(new Point(viewPos.x, Math.max(viewPos.y - scrollUnits.top, 0)));
        } else if ((viewPos.y + viewHeight - cursorLoc.y) < insets.bottom) { // scroll down
            viewport.setViewPosition(new Point(viewPos.x, Math.min(viewPos.y + scrollUnits.bottom, comp.getHeight()
                    - viewHeight)));
        } else if ((cursorLoc.x - viewPos.x) < insets.left) { // scroll left
            viewport.setViewPosition(new Point(Math.max(viewPos.x - scrollUnits.left, 0), viewPos.y));
        } else if ((viewPos.x + viewWidth - cursorLoc.x) < insets.right) { // scroll right
            viewport.setViewPosition(new Point(Math.min(viewPos.x + scrollUnits.right, comp.getWidth() - viewWidth),
                    viewPos.y));

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getExtentSize, getViewPosition, getViewSize
        } 
        int value = scroller.getValue();
        if (value != 0) {
            throw new Error("unexpected scroll value");
        } 
        int extent = viewport.getExtentSize().width;
        if (extent != scroller.getVisibleAmount()) {
            throw new Error("unexpected visible amount");
        } 
        int size = viewport.getViewSize().width;
        if (size != scroller.getMaximum()) {
            throw new Error("unexpected maximum");
        } 
        int pos = size - extent - value;
        if (pos != viewport.getViewPosition().x) {
            throw new Error("unexpected position");
        } 
    } 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getViewPosition, scrollRectToVisible
    // This rectangle is relative to the table where the 
    // northwest corner of cell (0,0) is always (0,0). 
    Rectangle rect = table.getCellRect(row, col, true);
     
    // The location of the viewport relative to the table 
    Point pt = viewport.getViewPosition();
     
    // Translate the cell location so that it is relative 
    // to the view, assuming the northwest corner of the 
    // view is (0,0) 
    rect.setLocation(rect.x - pt.x, rect.y - pt.y);
     
    // Scroll the area into view 
    viewport.scrollRectToVisible(rect);
  } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getView, setView
 
    @Override 
    public Component getToolComponent() {
        JViewport viewPort = rootPane.getViewport();
        if (viewPort == null) {
            viewPort = new JViewport();
            rootPane.setViewport(viewPort);
        } 
        if (viewPort.getView() != this) {
            viewPort.setView(this);
        } 
        return rootPane;
    } 
 
    @Override 
    protected void changeToolWindowAnchor(CLocation clocation) {
        // TODO Auto-generated method stub 
    } 
 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:add, removeAll
    public Point getViewPosition() {
        return vp.getViewPosition();
    } 
 
    public void add(JComponent c) {
        vp.removeAll();
        this.component = c;
        vp.add(c);
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getSize, setViewPosition
 
    progressFrame.pack();
    if(count > 15)
    { 
      JViewport vport = scroll.getViewport();
      vport.setViewPosition(
          new Point(0,vport.getSize().height));
    } 
 
    progressFrame.validate();
    ftprogress = new FTProgress(progress, filename);
 
    count++;
    return ftprogress;
  } 
 
  public void close() 
  {  
    progressFrame.setVisible(false);
    progressFrame.dispose();
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getViewRect, getViewSize, setViewPosition
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:addMouseListener, addMouseMotionListener
	 
	public DragMoverListener(JViewport vport, JComponent comp) {
		this.vport = vport;
		this.comp = comp;
		dc = comp.getCursor();
		vport.addMouseMotionListener(this);
		vport.addMouseListener(this);
	} 
	 
	@Override 
	public void mouseDragged(MouseEvent e) {
		log.debug("dragged"); 
		 
		if (e.getButton() == MouseEvent.BUTTON2) {
			Point pt = e.getPoint();
			move.setLocation(pt.x - startPt.x, pt.y - startPt.y);
			startPt.setLocation(pt);
			Rectangle vr = vport.getViewRect();
			int w = vr.width;
			int h = vr.height;
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getViewRect, scrollRectToVisible
	public void mouseDragged(MouseEvent e) {
		Point pt = e.getPoint();
		 
		int dx = pt.x - startPt.x;
		int dy = pt.y - startPt.y;
		Rectangle vr = vport.getViewRect();
		vr.setRect(vr.x - dx, vr.y - dy, vr.width, vr.height);
		vport.scrollRectToVisible(vr);
	} 
	 
	@Override 
	public void mousePressed(MouseEvent e) {
		comp.setCursor(hc);
		startPt.setLocation(e.getPoint());
	} 
	 
	@Override 
	public void mouseReleased(MouseEvent e) {
		comp.setCursor(dc);
	} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getParent, getViewPosition
	// 
	public void stateChanged(ChangeEvent e) {
		// Keep the scrolling of the row table in sync with main table 
 
		JViewport viewport = (JViewport) e.getSource();
		JScrollPane scrollPane = (JScrollPane) viewport.getParent();
		scrollPane.getVerticalScrollBar()
				.setValue(viewport.getViewPosition().y);
	} 
 
	// 
	// Implement the PropertyChangeListener 
	// 
	public void propertyChange(PropertyChangeEvent e) {
		// Keep the row table in sync with the main table 
 
		if ("selectionModel".equals(e.getPropertyName())) {
			setSelectionModel(main.getSelectionModel());
		} 
 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Java 8 JViewport Methods: