public void setScrollUpButton(AbstractButton scrollUpButton) { AbstractButton old = getScrollUpButton(); _scrollUpButton = scrollUpButton; add(_scrollUpButton, SCROLL_UP_BUTTON); firePropertyChange("scrollUpButton", old, _scrollUpButton); revalidate(); repaint(); }
@Override public void syncWithScrollPane(JScrollPane sp) { super.syncWithScrollPane(sp); if (sp instanceof SimpleScrollPane) { _scrollUp = ((SimpleScrollPane) sp).getScrollUpButton(); _scrollDown = ((SimpleScrollPane) sp).getScrollDownButton(); _scrollLeft = ((SimpleScrollPane) sp).getScrollLeftButton(); _scrollRight = ((SimpleScrollPane) sp).getScrollRightButton(); } }
public void stateChanged(ChangeEvent e) { if (e.getSource() instanceof JMenuItem) { if (((JMenuItem) e.getSource()).getModel().isArmed()) { popupMenu.scrollRectToVisible(((JMenuItem) e.getSource()).getBounds()); Point position = contents.getViewport().getViewPosition(); contents.getScrollUpButton().setEnabled(position.y > 2); contents.getScrollDownButton().setEnabled(position.y < contents.getViewport().getViewSize().height - contents.getViewport().getViewRect().height - 2); } } } });
public Dimension getPreferredScrollableViewportSize() { Dimension size = getPreferredSize(); Dimension screenSize = PortingUtils.getLocalScreenSize(this); Container container = SwingUtilities.getAncestorOfClass(SimpleScrollPane.class, this); if (container instanceof SimpleScrollPane) { SimpleScrollPane scrollPane = (SimpleScrollPane) container; int height = screenSize.height; // limit it to the height determined by the visible menu item count if (getVisibleMenuItemCount() > 0) { int totalHeight = getVisibleMenuItemCount() * getScrollableUnitIncrement(null, 0, 0); if (height > totalHeight) { height = totalHeight; } } size.height = Math.min(size.height, height - scrollPane.getScrollUpButton().getPreferredSize().height - scrollPane.getScrollDownButton().getPreferredSize().height); } return size; }
contents.getScrollUpButton().setOpaque(true); contents.getScrollDownButton().setOpaque(true); contents.setBorder(BorderFactory.createEmptyBorder());