Package javax.swing

Examples of javax.swing.JViewport


    // hack to make it non-opaque!
    try {
      Field field = JXCollapsiblePane.class.getDeclaredField("wrapper");
      field.setAccessible(true);
      JViewport viewPort = (JViewport) field.get(collapsiblePane);
      viewPort.setOpaque(false);
      JComponent component = (JComponent) viewPort.getView();
      component.setOpaque(false);
    } catch (Exception e) {
      logger.info("Failed to make JXCollapsiblePane non-opaque", e);
    }
    return collapsiblePane;
View Full Code Here


   * If this component is displayed in a viewport the view position is updated
   * to ensure the center's view will remain the same after the scale change.
   */
  public void setScale(float scale) {
    if (this.scale != scale) {
      JViewport parent = null;
      Rectangle viewRectangle = null;
      float xViewCenterPosition = 0;
      float yViewCenterPosition = 0;
      if (getParent() instanceof JViewport) {
        parent = (JViewport)getParent();
        viewRectangle = parent.getViewRect();
        xViewCenterPosition = (convertXPixelToModel(viewRectangle.x)
            + convertXPixelToModel(viewRectangle.x + viewRectangle.width)) / 2;
        yViewCenterPosition = (convertYPixelToModel(viewRectangle.y)
            + convertYPixelToModel(viewRectangle.y + viewRectangle.height)) / 2;
      }
     
      this.scale = scale;
      revalidate(false);

      if (parent instanceof JViewport) {
        Dimension viewSize = parent.getViewSize();
        float viewWidth = convertXPixelToModel(viewRectangle.x + viewRectangle.width)
            - convertXPixelToModel(viewRectangle.x);         
        int xViewLocation = Math.max(0, Math.min(convertXModelToPixel(xViewCenterPosition - viewWidth / 2),
            viewSize.width - viewRectangle.x));
        float viewHeight = convertYPixelToModel(viewRectangle.y + viewRectangle.height)
            - convertYPixelToModel(viewRectangle.y);         
        int yViewLocation = Math.max(0, Math.min(convertYModelToPixel(yViewCenterPosition - viewHeight / 2),
            viewSize.height - viewRectangle.y));       
        parent.setViewPosition(new Point(xViewLocation, yViewLocation));
      }
    }
  }
View Full Code Here

      float planBoundsNewMinX = (float)getPlanBounds().getMinX();
      float planBoundsNewMinY = (float)getPlanBounds().getMinY();
      // If plan bounds upper left corner diminished
      if (planBoundsNewMinX < planBoundsMinX
          || planBoundsNewMinY < planBoundsMinY) {
        JViewport parent = (JViewport)getParent();
        final Point viewPosition = parent.getViewPosition();
        Dimension extentSize = parent.getExtentSize();
        Dimension viewSize = parent.getViewSize();
        // Update view position when scroll bars are visible
        if (extentSize.width < viewSize.width
            || extentSize.height < viewSize.height) {
          int deltaX = Math.round((planBoundsMinX - planBoundsNewMinX) * getScale());
          int deltaY = Math.round((planBoundsMinY - planBoundsNewMinY) * getScale());
          parent.setViewPosition(new Point(viewPosition.x + deltaX, viewPosition.y + deltaY));
        }
      }
    }

    if (this.horizontalRuler != null) {
View Full Code Here

  /**
   * Moves the view from (dx, dy) unit in the scrolling zone it belongs to.
   */
  public void moveView(float dx, float dy) {
    if (getParent() instanceof JViewport) {
      JViewport viewport = (JViewport)getParent();
      Rectangle viewRectangle = viewport.getViewRect();
      viewRectangle.translate(Math.round(dx * getScale()), Math.round(dy * getScale()));
      viewRectangle.x = Math.min(Math.max(0, viewRectangle.x), getWidth() - viewRectangle.width);
      viewRectangle.y = Math.min(Math.max(0, viewRectangle.y), getHeight() - viewRectangle.height);
      viewport.setViewPosition(viewRectangle.getLocation());
    }
  }
View Full Code Here

    final JScrollPane scroll = new JScrollPane(html);
    scroll.setPreferredSize(new Dimension(500, 300));
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
          JViewport vp = scroll.getViewport();
          if(vp != null) {
            vp.setViewPosition(new Point(0,0));
            scroll.setViewport(vp);
          }
        }
      });
View Full Code Here

      // The viewport extent and size will be 0 during the first
      // layout (i.e., first call here) but the size of the panel will
      // be set, thus use it to guestimate the number of columns to
      // use.
      final JViewport viewport = scroll.getViewport();
      final Dimension viewportExtent = viewport.getExtentSize();
      final Dimension viewportSize = viewport.getSize();
      final Dimension size = getSize();

      if(viewportExtent.width != 0) {
        grid.setColumns(viewportExtent.width<w ? 1 : viewportExtent.width / w);
        grid.setRows(0);
View Full Code Here

  void setHTML(final String s) {
    html.setText(s);
    SwingUtilities.invokeLater(new Runnable() {
  public void run() {
    JViewport vp = scroll.getViewport();
    if(vp != null) {
      vp.setViewPosition(new Point(0,0));
      scroll.setViewport(vp);
   
  }
      });
  }
View Full Code Here

      html.setText(s);

      SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            try {
              JViewport vp = htmlScroll.getViewport();
              if(vp != null) {
                vp.setViewPosition(new Point(0,0));
                htmlScroll.setViewport(vp);
              }
            } catch (Exception e) {
              e.printStackTrace();
            }
View Full Code Here

   
    info.setEntry(entry);

    SwingUtilities.invokeLater(new Runnable() {
  public void run() {
    JViewport vp = scrollPane.getViewport();
    if(vp != null) {
      vp.setViewPosition(new Point(0,0));
      scrollPane.setViewport(vp);
    }
    if(table != null && model !=  null) {
      int row = model.getEntries().indexOf(entry);
      Rectangle r = table.getCellRect(row, 0, true);
View Full Code Here

    html.setText(s);

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
          try {
            JViewport vp = scroll.getViewport();
            if(vp != null) {
              vp.setViewPosition(new Point(0,0));
              scroll.setViewport(vp);
            }
          } catch (Exception e) {
            e.printStackTrace();
          }
View Full Code Here

TOP

Related Classes of javax.swing.JViewport

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.