javax.swing.JScrollPane#getViewport ( )源码实例Demo

下面列出了javax.swing.JScrollPane#getViewport ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: pcgen   文件: JDynamicTable.java
@Override
protected void unconfigureEnclosingScrollPane()
{
	super.unconfigureEnclosingScrollPane();
	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.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, null);
		}
	}
}
 
源代码2 项目: netbeans   文件: ETable.java
/**
 * 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());
    }
}
 
源代码3 项目: netbeans   文件: ZoomManager.java
public void actionPerformed(ActionEvent e) {
    Scene scene = manager.getScene();
    JScrollPane pane = (JScrollPane) SwingUtilities.getAncestorOfClass(
            JScrollPane.class, scene.getView());
    if (pane == null) {
        // Unlikely, but we cannot assume it exists.
        return;
    }
    JViewport viewport = pane.getViewport();
    Rectangle visRect = viewport.getViewRect();
    Rectangle compRect = scene.getPreferredBounds();
    int zoomX = visRect.width * 100 / compRect.width;
    int zoomY = visRect.height * 100 / compRect.height;
    int zoom = Math.min(zoomX, zoomY);
    manager.setZoom(zoom);
}
 
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;
}
 
源代码5 项目: gcs   文件: SheetDockable.java
/** Creates a new {@link SheetDockable}. */
public SheetDockable(GURPSCharacter character) {
    super(character);
    GURPSCharacter dataFile = getDataFile();
    mSheet = new CharacterSheet(dataFile);
    createToolbar();
    JScrollPane scroller = new JScrollPane(mSheet);
    scroller.setBorder(null);
    JViewport viewport = scroller.getViewport();
    viewport.setBackground(Color.LIGHT_GRAY);
    viewport.addChangeListener(mSheet);
    add(scroller, BorderLayout.CENTER);
    mSheet.rebuild();
    mSheet.getCharacter().processFeaturesAndPrereqs();
    dataFile.setModified(false);
    StdUndoManager undoManager = getUndoManager();
    undoManager.discardAllEdits();
    dataFile.setUndoManager(undoManager);
    dataFile.addTarget(this, Profile.ID_BODY_TYPE);
}
 
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;
}
 
源代码7 项目: pcgen   文件: JDynamicTable.java
@Override
protected void configureEnclosingScrollPane()
{
	super.configureEnclosingScrollPane();
	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.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
			scrollPane.setCorner(
					ScrollPaneConstants.UPPER_TRAILING_CORNER,
					wrappedCornerButton);
		}
	}
}
 
源代码8 项目: pcgen   文件: JDynamicTable.java
@Override
protected void unconfigureEnclosingScrollPane()
{
	super.unconfigureEnclosingScrollPane();
	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.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, null);
		}
	}
}
 
源代码9 项目: pcgen   文件: JTreeViewTable.java
@Override
protected void configureEnclosingScrollPane()
{
	super.configureEnclosingScrollPane();
	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.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
			scrollPane.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER,
					wrappedCornerButton);
		}
	}
}
 
源代码10 项目: pcgen   文件: JTreeViewTable.java
@Override
protected void unconfigureEnclosingScrollPane()
{
	super.unconfigureEnclosingScrollPane();
	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.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, null);
		}
	}
}
 
源代码11 项目: zap-extensions   文件: HttpFuzzerErrorsTable.java
/**
 * {@inheritDoc}
 *
 * <p>Overridden to take into account for possible parent {@code JLayer}s.
 *
 * @see javax.swing.JLayer
 */
// Note: Same implementation as in JXTable#getEnclosingScrollPane() but changed to get the
// parent and viewport view using
// the methods SwingUtilities#getUnwrappedParent(Component) and
// SwingUtilities#getUnwrappedView(JViewport) respectively.
@Override
protected JScrollPane getEnclosingScrollPane() {
    Container p = SwingUtilities.getUnwrappedParent(this);
    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 || SwingUtilities.getUnwrappedView(viewport) != this) {
                return null;
            }
            return scrollPane;
        }
    }
    return null;
}
 
源代码12 项目: pcgen   文件: JTreeViewTable.java
@Override
protected void configureEnclosingScrollPane()
{
	super.configureEnclosingScrollPane();
	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.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
			scrollPane.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER,
					wrappedCornerButton);
		}
	}
}
 
源代码13 项目: pcgen   文件: JDynamicTable.java
@Override
protected void configureEnclosingScrollPane()
{
	super.configureEnclosingScrollPane();
	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.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
			scrollPane.setCorner(
					ScrollPaneConstants.UPPER_TRAILING_CORNER,
					wrappedCornerButton);
		}
	}
}
 
源代码14 项目: netbeans   文件: PSheet.java
private JScrollPane createScrollPane(Component inner) {
    JScrollPane result = new JScrollPane(inner);
    JViewport vp = result.getViewport();
    vp.addMouseListener(this);

    MarginViewportUI ui = (MarginViewportUI) MarginViewportUI.createUI(vp);
    vp.setUI(ui);
    ui.setMarginPainted(marginPainted);
    ui.setMarginColor(marginColor);
    ui.setEmptyString(emptyString);
    result.setBorder(BorderFactory.createEmptyBorder());
    result.setViewportBorder(result.getBorder());

    return result;
}
 
源代码15 项目: netbeans   文件: ZoomManager.java
public void actionPerformed(ActionEvent e) {
    Scene scene = manager.getScene();
    JScrollPane pane = (JScrollPane) SwingUtilities.getAncestorOfClass(
            JScrollPane.class, scene.getView());
    if (pane == null) {
        // Unlikely, but we cannot assume it exists.
        return;
    }
    JViewport viewport = pane.getViewport();
    Rectangle visRect = viewport.getViewRect();
    Rectangle compRect = scene.getPreferredBounds();
    int zoom = visRect.width * 100 / compRect.width;
    manager.setZoom(zoom);
}
 
源代码16 项目: mzmine2   文件: FontBoxRenderer.java
private void manItemInCombo() {
  if (comboBox.getItemCount() > 0) {
    final Object comp = comboBox.getUI().getAccessibleChild(comboBox, 0);
    if ((comp instanceof JPopupMenu)) {
      final JList list = new JList(comboBox.getModel());
      final JPopupMenu popup = (JPopupMenu) comp;
      final JScrollPane scrollPane = (JScrollPane) popup.getComponent(0);
      final JViewport viewport = scrollPane.getViewport();
      final Rectangle rect = popup.getVisibleRect();
      final Point pt = viewport.getViewPosition();
      row = list.locationToIndex(pt);
    }
  }
}
 
源代码17 项目: netbeans   文件: DetailsPanel.java
private void initComponents() {        
    table = new DetailsTable();
    table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    JViewport viewport = new Viewport(table);

    final JScrollPane tableScroll = new JScrollPane(
                                        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                                        JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    tableScroll.setViewport(viewport);
    tableScroll.setBorder(BorderFactory.createEmptyBorder());
    tableScroll.setViewportBorder(BorderFactory.createEmptyBorder());
    tableScroll.setCorner(JScrollPane.UPPER_RIGHT_CORNER, new HeaderPanel());
    
    scrollBar = new ScrollBar(JScrollBar.VERTICAL) {
        public int getUnitIncrement(int direction) {
            JViewport vp = tableScroll.getViewport();
            Scrollable view = (Scrollable)(vp.getView());
            Rectangle vr = vp.getViewRect();
            return view.getScrollableUnitIncrement(vr, getOrientation(), direction);
        }
        public int getBlockIncrement(int direction) {
            JViewport vp = tableScroll.getViewport();
            Scrollable view = (Scrollable)(vp.getView());
            Rectangle vr = vp.getViewRect();
            return view.getScrollableBlockIncrement(vr, getOrientation(), direction);
        }
        public void setValues(int newValue, int newExtent, int newMin, int newMax) {
            setEnabled(newExtent < newMax);
            if (isEnabled() && !isSelectionChanging() && isTrackingEnd())
                newValue = newMax - newExtent;
            super.setValues(newValue, newExtent, newMin, newMax);
        }
    };
    tableScroll.setVerticalScrollBar(scrollBar);
    dataContainer = tableScroll;

    JLabel noDataLabel = new JLabel("<No probe selected>", JLabel.CENTER);
    noDataLabel.setEnabled(false);
    noDataContainer = new JPanel(new BorderLayout());
    noDataContainer.setOpaque(false);
    noDataContainer.add(noDataLabel, BorderLayout.CENTER);

    setOpaque(false);
    setLayout(new BorderLayout());
    add(noDataContainer, BorderLayout.CENTER);
}
 
源代码18 项目: visualvm   文件: DetailsPanel.java
private void initComponents() {        
    table = new DetailsTable();
    table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    JViewport viewport = new Viewport(table);

    final JScrollPane tableScroll = new JScrollPane(
                                        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                                        JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    tableScroll.setViewport(viewport);
    tableScroll.setBorder(BorderFactory.createEmptyBorder());
    tableScroll.setViewportBorder(BorderFactory.createEmptyBorder());
    tableScroll.setCorner(JScrollPane.UPPER_RIGHT_CORNER, new HeaderPanel());
    
    scrollBar = new ScrollBar(JScrollBar.VERTICAL) {
        public int getUnitIncrement(int direction) {
            JViewport vp = tableScroll.getViewport();
            Scrollable view = (Scrollable)(vp.getView());
            Rectangle vr = vp.getViewRect();
            return view.getScrollableUnitIncrement(vr, getOrientation(), direction);
        }
        public int getBlockIncrement(int direction) {
            JViewport vp = tableScroll.getViewport();
            Scrollable view = (Scrollable)(vp.getView());
            Rectangle vr = vp.getViewRect();
            return view.getScrollableBlockIncrement(vr, getOrientation(), direction);
        }
        public void setValues(int newValue, int newExtent, int newMin, int newMax) {
            setEnabled(newExtent < newMax);
            if (isEnabled() && !isSelectionChanging() && isTrackingEnd())
                newValue = newMax - newExtent;
            super.setValues(newValue, newExtent, newMin, newMax);
        }
    };
    tableScroll.setVerticalScrollBar(scrollBar);
    dataContainer = tableScroll;

    JLabel noDataLabel = new JLabel("<No probe selected>", JLabel.CENTER);
    noDataLabel.setEnabled(false);
    noDataContainer = new JPanel(new BorderLayout());
    noDataContainer.setOpaque(false);
    noDataContainer.add(noDataLabel, BorderLayout.CENTER);

    setOpaque(false);
    setLayout(new BorderLayout());
    add(noDataContainer, BorderLayout.CENTER);
}
 
源代码19 项目: visualvm   文件: DetailsPanel.java
private void initComponents() {        
    table = new DetailsTable();
    table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    JViewport viewport = new Viewport(table);

    final JScrollPane tableScroll = new JScrollPane(
                                        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                                        JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    tableScroll.setViewport(viewport);
    tableScroll.setBorder(BorderFactory.createEmptyBorder());
    tableScroll.setViewportBorder(BorderFactory.createEmptyBorder());
    tableScroll.setCorner(JScrollPane.UPPER_RIGHT_CORNER, new HeaderPanel());
    
    scrollBar = new ScrollBar(JScrollBar.VERTICAL) {
        public int getUnitIncrement(int direction) {
            JViewport vp = tableScroll.getViewport();
            Scrollable view = (Scrollable)(vp.getView());
            Rectangle vr = vp.getViewRect();
            return view.getScrollableUnitIncrement(vr, getOrientation(), direction);
        }
        public int getBlockIncrement(int direction) {
            JViewport vp = tableScroll.getViewport();
            Scrollable view = (Scrollable)(vp.getView());
            Rectangle vr = vp.getViewRect();
            return view.getScrollableBlockIncrement(vr, getOrientation(), direction);
        }
        public void setValues(int newValue, int newExtent, int newMin, int newMax) {
            setEnabled(newExtent < newMax);
            if (isEnabled() && !isSelectionChanging() && isTrackingEnd())
                newValue = newMax - newExtent;
            super.setValues(newValue, newExtent, newMin, newMax);
        }
    };
    tableScroll.setVerticalScrollBar(scrollBar);
    dataContainer = tableScroll;

    JLabel noDataLabel = new JLabel("<No probe selected>", JLabel.CENTER);
    noDataLabel.setEnabled(false);
    noDataContainer = new JPanel(new BorderLayout());
    noDataContainer.setOpaque(false);
    noDataContainer.add(noDataLabel, BorderLayout.CENTER);

    setOpaque(false);
    setLayout(new BorderLayout());
    add(noDataContainer, BorderLayout.CENTER);
}
 
源代码20 项目: mars-sim   文件: GuideWindow.java
public void init() {
		
		guideURL = getClass().getResource(Msg.getString("doc.guide")); //$NON-NLS-1$

		homeButton.setToolTipText(Msg.getString("GuideWindow.tooltip.home")); //$NON-NLS-1$
		homeButton.setSize(16, 16);
		homeButton.addActionListener(this);

		backButton.setToolTipText(Msg.getString("GuideWindow.tooltip.back")); //$NON-NLS-1$
		backButton.addActionListener(this);

		forwardButton.setToolTipText(Msg.getString("GuideWindow.tooltip.forward")); //$NON-NLS-1$
		forwardButton.addActionListener(this);

		// Create the main panel
		JPanel mainPane = new JPanel(new BorderLayout());
//		mainPane.setBorder(new MarsPanelBorder());
		setContentPane(mainPane);

		JPanel topPanel = new JPanel(new BorderLayout());
		mainPane.add(topPanel, BorderLayout.NORTH);
		
		// A toolbar to hold all our buttons
		JPanel homePanel = new JPanel(new FlowLayout(3, 3, FlowLayout.CENTER));
		topPanel.add(homePanel, BorderLayout.CENTER);
		
		homePanel.add(backButton);
		homePanel.add(homeButton);
		homePanel.add(forwardButton);
		
		JPanel linkPanel = new JPanel(new FlowLayout(3, 3, FlowLayout.TRAILING));
		topPanel.add(linkPanel, BorderLayout.EAST);
		
//		link = new WebLink(StyleId.linkShadow, new SvgIcon("github19"), WIKI_TEXT, new UrlLinkAction(WIKI_URL));
		link = new WebLink(StyleId.linkShadow, new UrlLinkAction(WIKI_URL));
//		link = new WebLink(StyleId.linkShadow, WIKI_TEXT, new UrlLinkAction(WIKI_URL));
		link.setAlignmentY(1f);
		link.setText(WIKI_TEXT);
//		link.setIcon(new SvgIcon("github.svg")); // github19
		TooltipManager.setTooltip(link, "Open mars-sim wiki in GitHub", TooltipWay.down);
		linkPanel.add(link);

		// Initialize the status bar
		mainPane.add(initializeStatusBar(),  BorderLayout.SOUTH);

		htmlPane = new HTMLContentPane();
		htmlPane.addHyperlinkListener(this);
		htmlPane.goToURL(guideURL);
		htmlPane.setContentType("text/html");
		htmlPane.setBackground(Color.lightGray);
		htmlPane.setBorder(new EmptyBorder(2, 2, 2, 2));

		JScrollPane scrollPane = new JScrollPane(htmlPane);
//		scrollPane.setBorder(new MarsPanelBorder());
		viewPort = (JViewport) scrollPane.getViewport();
//		viewPort.addComponentListener(this);
		viewPort.setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE);
		
		mainPane.add(scrollPane,  BorderLayout.CENTER);
		
		updateButtons();
		
		setResizable(false);
		setMaximizable(true);
		setVisible(true);
	
		setSize(new Dimension(800, 600));
//		setMinimumSize(new Dimension(320, 320));
//		setPreferredSize(new Dimension(800, 600));
//		setMaximumSize(new Dimension(1280, 600));
		
		Dimension desktopSize = desktop.getMainWindow().getFrame().getSize();
		Dimension windowSize = getSize();
//		System.out.println("desktopSize.width : " + desktopSize.width);
//		System.out.println("desktopSize.height : " + desktopSize.height);
		int width = (desktopSize.width - windowSize.width) / 2;
		int height = (desktopSize.height - windowSize.height - 100) / 2;
		setLocation(width, height);
		
		// Pack window.
		// WARNING: this will shrink the window to one line tall in swing mode
//		pack(); 

	}