当前位置: 首页>>代码示例>>Java>>正文


Java JViewport类代码示例

本文整理汇总了Java中javax.swing.JViewport的典型用法代码示例。如果您正苦于以下问题:Java JViewport类的具体用法?Java JViewport怎么用?Java JViewport使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JViewport类属于javax.swing包,在下文中一共展示了JViewport类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: focusGained

import javax.swing.JViewport; //导入依赖的package包/类
@Override
public void focusGained(FocusEvent e) {
    if (e.isTemporary()) {
        return;
    }
    Component cmp = e.getComponent();
    if(cmp instanceof JComponent) {
        JViewport vp = getViewport(container);
        if(vp == null) {
            return;
        }
        Rectangle vr = vp.getViewRect();
        Point p = SwingUtilities.convertPoint(cmp.getParent(), cmp.getLocation(), container);
        final Rectangle r = new Rectangle(p, cmp.getSize());
        if(vr.intersects(r)) {
            return; 
        }
        container.scrollRectToVisible(r);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:UIUtils.java

示例2: getExtentBounds

import javax.swing.JViewport; //导入依赖的package包/类
/** Get position of the component extent. The (x, y) are set to (0, 0) if there's
* no viewport or (-x, -y) if there's one.
*/
public Rectangle getExtentBounds(Rectangle r) {
    if (r == null) {
        r = new Rectangle();
    }
    if (component != null) {
        JViewport port = getParentViewport();
        if (port != null) {
            Point p = port.getViewPosition();
            r.width = port.getWidth();
            r.height = port.getHeight();
            r.x = p.x;
            r.y = p.y;
        } else { // no viewport
            r.setBounds(component.getVisibleRect());
        }
    }
    return r;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:EditorUI.java

示例3: changed

import javax.swing.JViewport; //导入依赖的package包/类
private void changed() {
    JViewport viewport = sp.getViewport();
    Point viewPosition = viewport.getViewPosition();
    if (viewPosition.x > 0) {
        try {
            Rectangle textRect = editorPane.getUI().modelToView(editorPane, editorPane.getDocument().getLength());
            int textLength = textRect.x + textRect.width;
            int viewLength = viewport.getExtentSize().width;
            //System.out.println("Utilities.createSingleLineEditor(): spLength = "+sp.getSize().width+", viewLength = "+viewLength+", textLength = "+textLength+", viewPosition = "+viewPosition);
            if (textLength < (viewPosition.x + viewLength)) {
                viewPosition.x = Math.max(textLength - viewLength, 0);
                viewport.setViewPosition(viewPosition);
                //System.out.println("Utilities.createSingleLineEditor(): setting new view position = "+viewPosition);
            }
        } catch (BadLocationException blex) {
            Exceptions.printStackTrace(blex);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:Utilities.java

示例4: computeVisibleSpan

import javax.swing.JViewport; //导入依赖的package包/类
private int[] computeVisibleSpan() {
    Component parent = pane.getParent();
    
    if (parent instanceof JLayeredPane) {
        parent = parent.getParent();
    }

    if (parent instanceof JViewport) {
        JViewport vp = (JViewport) parent;

        Point start = vp.getViewPosition();
        Dimension size = vp.getExtentSize();
        Point end = new Point((int) (start.getX() + size.getWidth()), (int) (start.getY() + size.getHeight()));

        int startPosition = pane.viewToModel(start);
        int endPosition = pane.viewToModel(end);

        if (parentWithListener != vp) {
            vp.addChangeListener(WeakListeners.change(this, vp));
            parentWithListener = vp;
        }
        return new int[] {startPosition, endPosition};
    }

    return new int[] {0, pane.getDocument().getLength()};
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ComponentPeer.java

示例5: getVisibleRowCount

import javax.swing.JViewport; //导入依赖的package包/类
protected int getVisibleRowCount() {
    int rowCount = getRowCount();
    int rowHeight = getRowHeight();

    if ((rowCount == 0) || (rowHeight == 0)) {
        return 0;
    }

    if (getParent() instanceof JViewport) {
        JViewport jvp = (JViewport) getParent();

        // +1 to return also half-displayed rows (issue 53660)
        int result = Math.min(rowCount, (jvp.getExtentSize().height / rowHeight) + 1);

        return result;
    } else {
        return Math.min(rowCount, getHeight() / rowHeight);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:BaseTable.java

示例6: hideSearchField

import javax.swing.JViewport; //导入依赖的package包/类
private void hideSearchField() {
    if (searchField == null) {
        return;
    }

    searchpanel.setVisible(false);

    if (getParent() instanceof JViewport && null != viewportListener ) {
        JViewport jvp = (JViewport) getParent();
        jvp.removeChangeListener( viewportListener );
        viewportListener = null;
    }
    
    getParent().removeComponentListener(searchField);
    if (searchpanel.getParent() != null) {
        searchpanel.getParent().remove(searchpanel);
    }

    paintSelectionRow();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:BaseTable.java

示例7: displaySearchField

import javax.swing.JViewport; //导入依赖的package包/类
/**
 * Adds the search field to the tree.
 */
private void displaySearchField(char initialChar) {
    if( null != searchpanel )
        return;
    JViewport vp = scrollPane.getViewport();
    originalScrollMode = vp.getScrollMode();
    vp.setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
    searchTextField.setFont(getFont());
    searchTextField.setText(String.valueOf(initialChar));
    prepareSearchPanel();
    scrollPane.add(searchpanel);
    invalidate();
    revalidate();
    repaint();
    searchTextField.requestFocus();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:PalettePanel.java

示例8: updateColumnSelectionMouseListener

import javax.swing.JViewport; //导入依赖的package包/类
/**
 * This method update mouse listener on the scrollPane if it is needed.
 * It also recomputes the model of searchCombo. Both actions are needed after
 * the set of visible columns is changed.
 */
void updateColumnSelectionMouseListener() {
    Container p = getParent();
    if (p instanceof JViewport) {
        Container gp = p.getParent();
        if (gp instanceof JScrollPane) {
            JScrollPane scrollPane = (JScrollPane)gp;
            // Make certain we are the viewPort's view and not, for
            // example, the rowHeaderView of the scrollPane -
            // an implementor of fixed columns might do this.
            JViewport viewport = scrollPane.getViewport();
            if (viewport == null || viewport.getView() != this) {
                return;
            }
            scrollPane.removeMouseListener(columnSelectionMouseListener);
            if (getColumnModel().getColumnCount() == 0) {
                scrollPane.addMouseListener(columnSelectionMouseListener);
            }
        }
    }
    if (searchCombo != null) {
        searchCombo.setModel(getSearchComboModel());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:ETable.java

示例9: recalculateCellSize

import javax.swing.JViewport; //导入依赖的package包/类
/**
 * Calculate the cell size to use given the current viewable region and the
 * the number of rows and columns in the grid. We use the largest
 * cellSize that will fit in the viewable region, bounded to be at least the
 * parameter minSize.
 */
private void recalculateCellSize(int minSize) {
    if (numRows == 0 || numCols == 0) {
        cellSize = 0;
    } else {
        JViewport vp = getEnclosingViewport();
        Dimension viewableSize = (vp != null) ? vp.getSize() : getSize();
        int desiredCellSize = Math.min(
                (viewableSize.height - extraHeight()) / numRows,
                (viewableSize.width - extraWidth()) / numCols) - 1;
        // now we want to approximate this with
        // DEFAULT_CELL_SIZE * Math.pow(2, k)
        cellSize = DEFAULT_CELL_SIZE;
        if (cellSize <= desiredCellSize)
            while (2 * cellSize <= desiredCellSize)
                cellSize *= 2;
        else
            while (cellSize / 2 >= Math.max(desiredCellSize, MIN_CELL_SIZE))
                cellSize /= 2;
    }
    revalidate();
}
 
开发者ID:CBSkarmory,项目名称:AWGW,代码行数:28,代码来源:GridPanel.java

示例10: validateThird

import javax.swing.JViewport; //导入依赖的package包/类
public void validateThird() {
    JViewport viewport = this.pane.getViewport();
    JScrollBar scroller = this.pane.getHorizontalScrollBar();
    if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {
        throw new Error("unexpected component orientation");
    }
    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");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:Test6526631.java

示例11: autoscroll

import javax.swing.JViewport; //导入依赖的package包/类
/** notify the Component to autoscroll */
public void autoscroll(Point cursorLoc) {
    JViewport viewport = getViewport();
    Point viewPos = viewport.getViewPosition();
    int viewHeight = viewport.getExtentSize().height;

    if ((cursorLoc.y - viewPos.y) <= realInsets.top) {
        // scroll up
        viewport.setViewPosition(new Point(viewPos.x, Math.max(viewPos.y - realInsets.top, 0)));
    } else if (((viewPos.y + viewHeight) - cursorLoc.y) <= realInsets.bottom) {
        // scroll down
        viewport.setViewPosition(
            new Point(viewPos.x, Math.min(viewPos.y + realInsets.bottom, this.getHeight() - viewHeight))
        );
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:IndexedCustomizer.java

示例12: showPopup

import javax.swing.JViewport; //导入依赖的package包/类
private void showPopup(Set<AppearancePort> portObjects) {
	dragStart = null;
	CircuitState circuitState = canvas.getCircuitState();
	if (circuitState == null)
		return;
	ArrayList<Instance> ports = new ArrayList<Instance>(portObjects.size());
	for (AppearancePort portObject : portObjects) {
		ports.add(portObject.getPin());
	}

	hideCurrentPopup();
	LayoutThumbnail layout = new LayoutThumbnail();
	layout.setCircuit(circuitState, ports);
	JViewport owner = canvasPane.getViewport();
	Point ownerLoc = owner.getLocationOnScreen();
	Dimension ownerDim = owner.getSize();
	Dimension layoutDim = layout.getPreferredSize();
	int x = ownerLoc.x + Math.max(0, ownerDim.width - layoutDim.width - 5);
	int y = ownerLoc.y + Math.max(0, ownerDim.height - layoutDim.height - 5);
	PopupFactory factory = PopupFactory.getSharedInstance();
	Popup popup = factory.getPopup(canvasPane.getViewport(), layout, x, y);
	popup.show();
	curPopup = popup;
	curPopupTime = System.currentTimeMillis();
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:26,代码来源:LayoutPopupManager.java

示例13: createComponent

import javax.swing.JViewport; //导入依赖的package包/类
private static JComponent createComponent() {
    createStyles();
    for (int i = 0; i < data.length; i++) {
        Paragraph p = data[i];
        addParagraph(p);
    }

    JTextPane textPane = new JTextPane(doc);

    JScrollPane scroller = new JScrollPane();
    JViewport port = scroller.getViewport();
    port.setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE);
    port.add(textPane);

    return scroller;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:JViewPortBackingStoreImageTest.java

示例14: getColumnLocation

import javax.swing.JViewport; //导入依赖的package包/类
/**
 * 
 */
public int getColumnLocation(mxCellState edge, mxCellState terminal, int column) {
  Component[] c = components.get(terminal.getCell());
  int y = 0;

  if (c != null) {
    for (int i = 0; i < c.length; i++) {
      if (c[i] instanceof JTableRenderer) {
        JTableRenderer vertex = (JTableRenderer) c[i];

        JTable table = vertex.table;
        JViewport viewport = (JViewport) table.getParent();
        double dy = -viewport.getViewPosition().getY();
        y = (int) Math.max(terminal.getY() + 22,
            terminal.getY() + Math.min(terminal.getHeight() - 20, 30 + dy + column * 16));
      }
    }
  }

  return y;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:24,代码来源:SchemaGraphComponent.java

示例15: Limpar_Campos_Tela

import javax.swing.JViewport; //导入依赖的package包/类
public static void Limpar_Campos_Tela(JPanel tela, Boolean bloquear_Componentes){
    for (Component componente : tela.getComponents()) {
        if (componente instanceof JPanel) {
            Limpar_Campos_Tela((JPanel) componente,bloquear_Componentes);
        }
        if(componente instanceof JScrollPane){
            JViewport viewport = ((JScrollPane)componente).getViewport(); 
            JTable table = (JTable)viewport.getView();
            
            DefaultTableModel model = (DefaultTableModel) table.getModel();
            model.getDataVector().removeAllElements();
            model.fireTableDataChanged();
            
            table.setEnabled(!bloquear_Componentes);
        }
        if (componente instanceof JTextField) {
            ((JTextField) componente).setText("");
            ((JTextField) componente).setEnabled(!bloquear_Componentes);
        }
        if (componente instanceof JFormattedTextField) {
            ((JFormattedTextField) componente).setText("");
            ((JFormattedTextField) componente).setEnabled(!bloquear_Componentes);
        }
        if(componente instanceof JButton){
            ((JButton) componente).setEnabled(!bloquear_Componentes);
        }
    }
}
 
开发者ID:iuryamicussi,项目名称:TrabalhoCrisParte2,代码行数:29,代码来源:Generica.java


注:本文中的javax.swing.JViewport类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。