Java Code Examples for javax.swing.JScrollPane#getHorizontalScrollBar()

The following examples show how to use javax.swing.JScrollPane#getHorizontalScrollBar() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Outline.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
      public void componentMoved(ComponentEvent e) {
   if(timer == null) {
JScrollPane   scrollPane = getScrollPane();

if(scrollPane == null) {
    change();
              } else {
    scrollBar = scrollPane.getVerticalScrollBar();
    if(scrollBar == null || 
	!scrollBar.getValueIsAdjusting()) {
	// Try the horizontal scrollbar.
	if((scrollBar = scrollPane.getHorizontalScrollBar())
	    != null && scrollBar.getValueIsAdjusting()) {
                              
	    startTimer();
                      } else {
	    change();
                      }
    } else {
	startTimer();
                  }
}
   }
      }
 
Example 2
Source File: MBasicTable.java    From javamelody with Apache License 2.0 6 votes vote down vote up
@Override
protected void configureEnclosingScrollPane() {
	// Si cette table est la viewportView d'un JScrollPane (la situation habituelle),
	// configure ce ScrollPane en positionnant la barre verticale à "always"
	// (et en installant le tableHeader comme columnHeaderView).
	super.configureEnclosingScrollPane();

	final Container parent = getParent();
	if (parent instanceof JViewport && parent.getParent() instanceof JScrollPane) {
		final JScrollPane scrollPane = (JScrollPane) parent.getParent();
		if (scrollPane.getVerticalScrollBar() != null) {
			scrollPane.getVerticalScrollBar().setFocusable(false);
		}
		if (scrollPane.getHorizontalScrollBar() != null) {
			scrollPane.getHorizontalScrollBar().setFocusable(false);
		}

		final JViewport viewport = scrollPane.getViewport();
		if (viewport == null || viewport.getView() != this) {
			return;
		}

		scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
	}
}
 
Example 3
Source File: XTextAreaPeer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void installDefaults(JScrollPane scrollpane) {
    Border b = scrollpane.getBorder();
    UIDefaults uidefaults = XToolkit.getUIDefaults();
    scrollpane.setBorder(uidefaults.getBorder("ScrollPane.border"));
    scrollpane.setBackground(uidefaults.getColor("ScrollPane.background"));
    scrollpane.setViewportBorder(uidefaults.getBorder("TextField.border"));
    JScrollBar vsb = scrollpane.getVerticalScrollBar();
    if (vsb != null) {
        if (isLeftToRight(scrollpane)) {
            vsbBorder = new CompoundBorder(vsbMarginBorderR,
                                           vsb.getBorder());
        }
        else {
            vsbBorder = new CompoundBorder(vsbMarginBorderL,
                                           vsb.getBorder());
        }
        vsb.setBorder(vsbBorder);
    }

    JScrollBar hsb = scrollpane.getHorizontalScrollBar();
    if (hsb != null) {
        hsbBorder = new CompoundBorder(hsbMarginBorder, hsb.getBorder());
        hsb.setBorder(hsbBorder);
    }
}
 
Example 4
Source File: XTextAreaPeer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void installDefaults(JScrollPane scrollpane) {
    Border b = scrollpane.getBorder();
    UIDefaults uidefaults = XToolkit.getUIDefaults();
    scrollpane.setBorder(uidefaults.getBorder("ScrollPane.border"));
    scrollpane.setBackground(uidefaults.getColor("ScrollPane.background"));
    scrollpane.setViewportBorder(uidefaults.getBorder("TextField.border"));
    JScrollBar vsb = scrollpane.getVerticalScrollBar();
    if (vsb != null) {
        if (isLeftToRight(scrollpane)) {
            vsbBorder = new CompoundBorder(vsbMarginBorderR,
                                           vsb.getBorder());
        }
        else {
            vsbBorder = new CompoundBorder(vsbMarginBorderL,
                                           vsb.getBorder());
        }
        vsb.setBorder(vsbBorder);
    }

    JScrollBar hsb = scrollpane.getHorizontalScrollBar();
    if (hsb != null) {
        hsbBorder = new CompoundBorder(hsbMarginBorder, hsb.getBorder());
        hsb.setBorder(hsbBorder);
    }
}
 
Example 5
Source File: TracerDataCompareView.java    From pega-tracerviewer with Apache License 2.0 5 votes vote down vote up
protected void syncScrollBars() {

        JScrollPane jscrollPaneLeft = getjscrollPaneLeft();
        JScrollPane jscrollPaneRight = getjscrollPaneRight();

        JScrollBar jscrollBarLeftH = jscrollPaneLeft.getHorizontalScrollBar();
        JScrollBar jscrollBarLeftV = jscrollPaneLeft.getVerticalScrollBar();
        JScrollBar jscrollBarRightH = jscrollPaneRight.getHorizontalScrollBar();
        JScrollBar jscrollBarRightV = jscrollPaneRight.getVerticalScrollBar();

        jscrollBarRightH.setModel(jscrollBarLeftH.getModel());
        jscrollBarRightV.setModel(jscrollBarLeftV.getModel());
    }
 
Example 6
Source File: SmartScroller.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
/**
 *  Specify how the SmartScroller will function.
 *
 *  @param scrollPane the scroll pane to monitor
 *  @param scrollDirection indicates which JScrollBar to monitor.
 *                         Valid values are HORIZONTAL and VERTICAL.
 *  @param viewportPosition indicates where the viewport will normally be
 *                          positioned as data is added.
 *                          Valid values are START and END
 */
public SmartScroller(JScrollPane scrollPane, int scrollDirection, int viewportPosition)
{
	if (scrollDirection != HORIZONTAL
	&&  scrollDirection != VERTICAL)
		throw new IllegalArgumentException("invalid scroll direction specified");

	if (viewportPosition != START
	&&  viewportPosition != END)
		throw new IllegalArgumentException("invalid viewport position specified");

	this.viewportPosition = viewportPosition;

	if (scrollDirection == HORIZONTAL)
		scrollBar = scrollPane.getHorizontalScrollBar();
	else
		scrollBar = scrollPane.getVerticalScrollBar();

	scrollBar.addAdjustmentListener( this );

	//  Turn off automatic scrolling for text components

	Component view = scrollPane.getViewport().getView();

	if (view instanceof JTextComponent)
	{
		JTextComponent textComponent = (JTextComponent)view;
		DefaultCaret caret = (DefaultCaret)textComponent.getCaret();
		caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
	}
}
 
Example 7
Source File: BaseCaret.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public @Override void propertyChange(PropertyChangeEvent evt) {
    String propName = evt.getPropertyName();
    if ("document".equals(propName)) { // NOI18N
        BaseDocument newDoc = (evt.getNewValue() instanceof BaseDocument)
                              ? (BaseDocument)evt.getNewValue() : null;
        modelChanged(listenDoc, newDoc);

    } else if (EditorUI.OVERWRITE_MODE_PROPERTY.equals(propName)) {
        Boolean b = (Boolean)evt.getNewValue();
        overwriteMode = (b != null) ? b.booleanValue() : false;
        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.
        Container parent = component.getParent();
        if (parent instanceof JViewport) {
            parent = parent.getParent(); // parent of viewport
            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();
        }
    }
}
 
Example 8
Source File: EditorCaret.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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);
                }
            }
        }
 
Example 9
Source File: WhiteBackgroundLookAndFeel.java    From neembuu-uploader with GNU General Public License v3.0 4 votes vote down vote up
public static void themeScrolls(JScrollPane jsp){
    if(jsp.getHorizontalScrollBar()!=null)
        themedScrollBar(jsp.getHorizontalScrollBar());
    if(jsp.getVerticalScrollBar()!=null)
        themedScrollBar(jsp.getVerticalScrollBar());
}
 
Example 10
Source File: CustomScroll.java    From mars-sim with GNU General Public License v3.0 3 votes vote down vote up
public CustomScroll(JComponent component) {
        scr = new JScrollPane(component);
        scr.setBorder(null);
        scr.setViewportBorder(null);
        scr.setBorder(BorderFactory.createEmptyBorder());
        scr.getViewport().setOpaque(false);
//        scr.setOpaque(false);
//        scr.setBackground(new Color(0, 0, 0, 5));
        verticalScrollBar = scr.getVerticalScrollBar();
        verticalScrollBar.setVisible(false);
        verticalScrollBar.setOpaque(false);
        verticalScrollBar.setUI(new MyScrollBarUI());
        verticalScrollBar.setUnitIncrement(16);

        horizontalScrollBar = scr.getHorizontalScrollBar();
        horizontalScrollBar.setVisible(false);
        horizontalScrollBar.setOpaque(false);
        horizontalScrollBar.setUI(new MyScrollBarUI());

        JLayeredPane layeredPane = new JLayeredPane();
        layeredPane.setLayer(verticalScrollBar, JLayeredPane.PALETTE_LAYER);
        layeredPane.setLayer(horizontalScrollBar, JLayeredPane.PALETTE_LAYER);

        scr.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        scr.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scr.setLayout(new ScrollPaneLayout() {
            @Override
            public void layoutContainer(Container parent) {
                viewport.setBounds(0, 0, getWidth(), getHeight());
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        displayScrollBarsIfNecessary(viewport);
                    }
                });
            }
        });

        layeredPane.add(horizontalScrollBar);
        layeredPane.add(verticalScrollBar);
        layeredPane.add(scr);

        setLayout(new BorderLayout() {
            @Override
            public void layoutContainer(Container target) {
                super.layoutContainer(target);
                int width = getWidth();
                int height = getHeight();
                scr.setBounds(0, 0, width, height);

                int scrollBarSize = 10;
                int cornerOffset = verticalScrollBar.isVisible() &&
                        horizontalScrollBar.isVisible() ? scrollBarSize : 0;
                if (verticalScrollBar.isVisible()) {
                    verticalScrollBar.setBounds(width - scrollBarSize, 0,
                            scrollBarSize, height - cornerOffset);
                }
                if (horizontalScrollBar.isVisible()) {
                    horizontalScrollBar.setBounds(0, height - scrollBarSize,
                            width - cornerOffset, scrollBarSize);
                }
            }
        });
        add(layeredPane, BorderLayout.CENTER);
        layeredPane.setBackground(Color.BLUE);
    }