下面列出了javax.swing.JViewport#getParent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void stateChanged(ChangeEvent e)
{
// Keep the scrolling of the row table in sync with main table
JViewport viewport = (JViewport) e.getSource();
JScrollPane scrollPane = (JScrollPane)viewport.getParent();
scrollPane.setBorder(new MarsPanelBorder());
scrollPane.getVerticalScrollBar().setValue(viewport.getViewPosition().y);
}
public void stateChanged(ChangeEvent e) {
// Keep the scrolling of the row table in sync with main table
JViewport viewport = (JViewport) e.getSource();
JScrollPane scrollPane = (JScrollPane) viewport.getParent();
scrollPane.getVerticalScrollBar()
.setValue(viewport.getViewPosition().y);
}
public @Override void propertyChange(PropertyChangeEvent evt) {
String propName = evt.getPropertyName();
JTextComponent c = component;
if ("document".equals(propName)) { // NOI18N
if (c != null) {
modelChanged(activeDoc, c.getDocument());
}
} else if (EditorUtilities.CARET_OVERWRITE_MODE_PROPERTY.equals(propName)) {
Boolean b = (Boolean) evt.getNewValue();
overwriteMode = (b != null) ? b : false;
updateOverwriteModeLayer(true);
updateType();
} else if ("ancestor".equals(propName) && evt.getSource() == component) { // NOI18N
// The following code ensures that when the width of the line views
// gets computed on background after the file gets opened
// (so the horizontal scrollbar gets added after several seconds
// for larger files) that the suddenly added horizontal scrollbar
// will not hide the caret laying on the last line of the viewport.
// A component listener gets installed into horizontal scrollbar
// and if it's fired the caret's bounds will be checked whether
// they intersect with the horizontal scrollbar
// and if so the view will be scrolled.
final JViewport viewport = getViewport();
if (viewport != null) {
Component parent = viewport.getParent();
if (parent instanceof JScrollPane) {
JScrollPane scrollPane = (JScrollPane) parent;
JScrollBar hScrollBar = scrollPane.getHorizontalScrollBar();
if (hScrollBar != null) {
// Add weak listener so that editor pane could be removed
// from scrollpane without being held by scrollbar
hScrollBar.addComponentListener(
(ComponentListener) WeakListeners.create(
ComponentListener.class, listenerImpl, hScrollBar));
}
}
}
} else if ("enabled".equals(propName)) {
Boolean enabled = (Boolean) evt.getNewValue();
if (component.isFocusOwner()) {
if (enabled == Boolean.TRUE) {
if (component.isEditable()) {
setVisible(true);
}
setSelectionVisible(true);
} else {
setVisible(false);
setSelectionVisible(false);
}
}
} else if (RECTANGULAR_SELECTION_PROPERTY.equals(propName)) {
boolean origRectangularSelection = rectangularSelection;
rectangularSelection = Boolean.TRUE.equals(component.getClientProperty(RECTANGULAR_SELECTION_PROPERTY));
if (rectangularSelection != origRectangularSelection) {
if (rectangularSelection) {
setRectangularSelectionToDotAndMark();
// RectangularSelectionTransferHandler.install(component);
} else { // No rectangular selection
// RectangularSelectionTransferHandler.uninstall(component);
}
fireStateChanged(null);
}
}
}