下面列出了javax.swing.SwingUtilities#getUnwrappedParent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* {@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;
}
@Override
public boolean getScrollableTracksViewportWidth() {
if (lineWrap)
return super.getScrollableTracksViewportWidth();
else {
Container parent = SwingUtilities.getUnwrappedParent(this);
return parent == null || getUI().getPreferredSize(this).width <= parent.getSize().width;
}
}
@Override
public boolean getScrollableTracksViewportWidth() {
Container parent = SwingUtilities.getUnwrappedParent(this);
if (parent instanceof JViewport) {
return parent.getWidth() > getPreferredSize().width;
}
return false;
}
@Override
public boolean getScrollableTracksViewportHeight() {
Container parent = SwingUtilities.getUnwrappedParent(this);
if (parent instanceof JViewport) {
return parent.getHeight() > getPreferredSize().height;
}
return false;
}
@Override
public boolean getScrollableTracksViewportWidth() {
if (lineWrap)
return super.getScrollableTracksViewportWidth();
else {
Container parent = SwingUtilities.getUnwrappedParent(this);
return parent == null || getUI().getPreferredSize(this).width <= parent.getSize().width;
}
}
private JScrollPane getEnclosingScrollPane() {
Container parent = SwingUtilities.getUnwrappedParent(this);
if (!(parent instanceof JViewport)) return null;
Container scroll = ((JViewport)parent).getParent();
return scroll instanceof JScrollPane ? (JScrollPane)scroll : null;
}
private JScrollPane getEnclosingScrollPane() {
Container parent = SwingUtilities.getUnwrappedParent(this);
if (!(parent instanceof JViewport)) return null;
Container scroll = ((JViewport)parent).getParent();
return scroll instanceof JScrollPane ? (JScrollPane)scroll : null;
}