當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。