Java Code Examples for javax.swing.JScrollBar#addAdjustmentListener()

The following examples show how to use javax.swing.JScrollBar#addAdjustmentListener() . 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: LWScrollBarPeer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
void initializeImpl() {
    super.initializeImpl();
    final Scrollbar target = getTarget();
    setLineIncrement(target.getUnitIncrement());
    setPageIncrement(target.getBlockIncrement());
    setValues(target.getValue(), target.getVisibleAmount(),
              target.getMinimum(), target.getMaximum());

    final int orientation = target.getOrientation();
    final JScrollBar delegate = getDelegate();
    synchronized (getDelegateLock()) {
        delegate.setOrientation(orientation == Scrollbar.HORIZONTAL
                                ? Adjustable.HORIZONTAL
                                : Adjustable.VERTICAL);
        delegate.addAdjustmentListener(this);
    }
}
 
Example 2
Source File: LWScrollBarPeer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
void initializeImpl() {
    super.initializeImpl();
    final Scrollbar target = getTarget();
    setLineIncrement(target.getUnitIncrement());
    setPageIncrement(target.getBlockIncrement());
    setValues(target.getValue(), target.getVisibleAmount(),
              target.getMinimum(), target.getMaximum());

    final int orientation = target.getOrientation();
    final JScrollBar delegate = getDelegate();
    synchronized (getDelegateLock()) {
        delegate.setOrientation(orientation == Scrollbar.HORIZONTAL
                                ? Adjustable.HORIZONTAL
                                : Adjustable.VERTICAL);
        delegate.addAdjustmentListener(this);
    }
}
 
Example 3
Source File: LWScrollBarPeer.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
void initializeImpl() {
    super.initializeImpl();
    final Scrollbar target = getTarget();
    setLineIncrement(target.getUnitIncrement());
    setPageIncrement(target.getBlockIncrement());
    setValues(target.getValue(), target.getVisibleAmount(),
              target.getMinimum(), target.getMaximum());

    final int orientation = target.getOrientation();
    final JScrollBar delegate = getDelegate();
    synchronized (getDelegateLock()) {
        delegate.setOrientation(orientation == Scrollbar.HORIZONTAL
                                ? Adjustable.HORIZONTAL
                                : Adjustable.VERTICAL);
        delegate.addAdjustmentListener(this);
    }
}
 
Example 4
Source File: LWScrollBarPeer.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
void initializeImpl() {
    super.initializeImpl();
    final Scrollbar target = getTarget();
    setLineIncrement(target.getUnitIncrement());
    setPageIncrement(target.getBlockIncrement());
    setValues(target.getValue(), target.getVisibleAmount(),
              target.getMinimum(), target.getMaximum());

    final int orientation = target.getOrientation();
    final JScrollBar delegate = getDelegate();
    synchronized (getDelegateLock()) {
        delegate.setOrientation(orientation == Scrollbar.HORIZONTAL
                                ? Adjustable.HORIZONTAL
                                : Adjustable.VERTICAL);
        delegate.addAdjustmentListener(this);
    }
}
 
Example 5
Source File: LWScrollBarPeer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
void initializeImpl() {
    super.initializeImpl();
    final Scrollbar target = getTarget();
    setLineIncrement(target.getUnitIncrement());
    setPageIncrement(target.getBlockIncrement());
    setValues(target.getValue(), target.getVisibleAmount(),
              target.getMinimum(), target.getMaximum());

    final int orientation = target.getOrientation();
    final JScrollBar delegate = getDelegate();
    synchronized (getDelegateLock()) {
        delegate.setOrientation(orientation == Scrollbar.HORIZONTAL
                                ? Adjustable.HORIZONTAL
                                : Adjustable.VERTICAL);
        delegate.addAdjustmentListener(this);
    }
}
 
Example 6
Source File: LWScrollBarPeer.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
void initializeImpl() {
    super.initializeImpl();
    final Scrollbar target = getTarget();
    setLineIncrement(target.getUnitIncrement());
    setPageIncrement(target.getBlockIncrement());
    setValues(target.getValue(), target.getVisibleAmount(),
              target.getMinimum(), target.getMaximum());

    final int orientation = target.getOrientation();
    final JScrollBar delegate = getDelegate();
    synchronized (getDelegateLock()) {
        delegate.setOrientation(orientation == Scrollbar.HORIZONTAL
                                ? Adjustable.HORIZONTAL
                                : Adjustable.VERTICAL);
        delegate.addAdjustmentListener(this);
    }
}
 
Example 7
Source File: LWScrollBarPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
void initializeImpl() {
    super.initializeImpl();
    final Scrollbar target = getTarget();
    setLineIncrement(target.getUnitIncrement());
    setPageIncrement(target.getBlockIncrement());
    setValues(target.getValue(), target.getVisibleAmount(),
              target.getMinimum(), target.getMaximum());

    final int orientation = target.getOrientation();
    final JScrollBar delegate = getDelegate();
    synchronized (getDelegateLock()) {
        delegate.setOrientation(orientation == Scrollbar.HORIZONTAL
                                ? Adjustable.HORIZONTAL
                                : Adjustable.VERTICAL);
        delegate.addAdjustmentListener(this);
    }
}
 
Example 8
Source File: LWScrollBarPeer.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
void initializeImpl() {
    super.initializeImpl();
    final Scrollbar target = getTarget();
    setLineIncrement(target.getUnitIncrement());
    setPageIncrement(target.getBlockIncrement());
    setValues(target.getValue(), target.getVisibleAmount(),
              target.getMinimum(), target.getMaximum());

    final int orientation = target.getOrientation();
    final JScrollBar delegate = getDelegate();
    synchronized (getDelegateLock()) {
        delegate.setOrientation(orientation == Scrollbar.HORIZONTAL
                                ? Adjustable.HORIZONTAL
                                : Adjustable.VERTICAL);
        delegate.addAdjustmentListener(this);
    }
}
 
Example 9
Source File: LWScrollBarPeer.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
void initializeImpl() {
    super.initializeImpl();
    final Scrollbar target = getTarget();
    setLineIncrement(target.getUnitIncrement());
    setPageIncrement(target.getBlockIncrement());
    setValues(target.getValue(), target.getVisibleAmount(),
              target.getMinimum(), target.getMaximum());

    final int orientation = target.getOrientation();
    final JScrollBar delegate = getDelegate();
    synchronized (getDelegateLock()) {
        delegate.setOrientation(orientation == Scrollbar.HORIZONTAL
                                ? Adjustable.HORIZONTAL
                                : Adjustable.VERTICAL);
        delegate.addAdjustmentListener(this);
    }
}
 
Example 10
Source File: LWScrollBarPeer.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
void initializeImpl() {
    super.initializeImpl();
    final Scrollbar target = getTarget();
    setLineIncrement(target.getUnitIncrement());
    setPageIncrement(target.getBlockIncrement());
    setValues(target.getValue(), target.getVisibleAmount(),
              target.getMinimum(), target.getMaximum());

    final int orientation = target.getOrientation();
    final JScrollBar delegate = getDelegate();
    synchronized (getDelegateLock()) {
        delegate.setOrientation(orientation == Scrollbar.HORIZONTAL
                                ? Adjustable.HORIZONTAL
                                : Adjustable.VERTICAL);
        delegate.addAdjustmentListener(this);
    }
}
 
Example 11
Source File: LWScrollBarPeer.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
void initializeImpl() {
    super.initializeImpl();
    final Scrollbar target = getTarget();
    setLineIncrement(target.getUnitIncrement());
    setPageIncrement(target.getBlockIncrement());
    setValues(target.getValue(), target.getVisibleAmount(),
              target.getMinimum(), target.getMaximum());

    final int orientation = target.getOrientation();
    final JScrollBar delegate = getDelegate();
    synchronized (getDelegateLock()) {
        delegate.setOrientation(orientation == Scrollbar.HORIZONTAL
                                ? Adjustable.HORIZONTAL
                                : Adjustable.VERTICAL);
        delegate.addAdjustmentListener(this);
    }
}
 
Example 12
Source File: InteractiveCanvasComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void attachScrollBar(JScrollBar scrollBar, boolean horizontal) {
    if (this.scrollBar == scrollBar) return;
    if (this.scrollBar != null) detachScrollBar();
    this.scrollBar = scrollBar;
    this.horizontal = horizontal;
    scrollBar.addAdjustmentListener(this);
    scrollBar.addMouseWheelListener(this);
    if (!horizontal)
        InteractiveCanvasComponent.this.addMouseWheelListener(this);
}
 
Example 13
Source File: LogViewer.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
public LogScrollPane(Component aView) {

            super(aView);

            final JScrollBar vscroll = getVerticalScrollBar();
            vscroll.setUnitIncrement(INCREMENT);
            vscroll.setBlockIncrement(INCREMENT);
            vscroll.addAdjustmentListener(e -> e.getAdjustable().setValue(e.getAdjustable().getMaximum()));

            setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
            setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);

            setBorder(BorderFactory.createEmptyBorder());
            getViewport().setOpaque(false);
        }
 
Example 14
Source File: SymbolControl.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void initComponents() {
    this.setPreferredSize(new Dimension(200, 100));
    this.setLayout(new BorderLayout());
    this.setBackground(Color.white);

    _vScrollBar = new JScrollBar(JScrollBar.VERTICAL);
    _vScrollBar.addAdjustmentListener(new AdjustmentListener() {
        @Override
        public void adjustmentValueChanged(AdjustmentEvent e) {
            onScrollValueChanged(e);
        }
    });
    this.add(_vScrollBar, BorderLayout.EAST);
    //this._vScrollBar.setSize(this._vScrollBar.getWidth(), this.getHeight());
    this._vScrollBar.setSize(20, this.getHeight());
    this._vScrollBar.setLocation(this.getWidth() - this._vScrollBar.getWidth(), 0);
}
 
Example 15
Source File: ScrollablePopupMenu.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
public ScrollablePopupMenu(String label) {
	super(label);

	// First component is the scroll bar
	scrollBar = new JScrollBar();
	scrollBar.setVisible(false);
	scrollBar.addAdjustmentListener(new AdjustmentListener() {
		@Override
		public void adjustmentValueChanged(AdjustmentEvent e) {
			doLayout();
			repaint();
		}
	});
	super.add(scrollBar);

	// Use a customised LayoutManager to position the scroll bar correctly
	setLayout(new ScrollableMenuLayout());

	// Respond to the mouse wheel
	addMouseWheelListener(new MouseWheelListener() {
		@Override
		public void mouseWheelMoved(MouseWheelEvent event) {
			int amount = (event.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL)
					? event.getUnitsToScroll() * scrollBar.getUnitIncrement()
					: (event.getWheelRotation() < 0 ? -1 : 1) * scrollBar.getBlockIncrement();

			scrollBar.setValue(scrollBar.getValue() + amount);
			event.consume();
		}
	});
}
 
Example 16
Source File: InteractiveCanvasComponent.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void attachScrollBar(JScrollBar scrollBar, boolean horizontal) {
    if (this.scrollBar == scrollBar) return;
    if (this.scrollBar != null) detachScrollBar();
    this.scrollBar = scrollBar;
    this.horizontal = horizontal;
    scrollBar.addAdjustmentListener(this);
    scrollBar.addMouseWheelListener(this);
    if (!horizontal)
        InteractiveCanvasComponent.this.addMouseWheelListener(this);
}
 
Example 17
Source File: CourseTabFactory.java    From tmc-intellij with MIT License 5 votes vote down vote up
private void setScrollBarToBottom(String course,
                                  JTabbedPane tabbedPanelBase,
                                  JBScrollPane panel) {

    tabbedPanelBase.addTab(course, panel);
    JScrollBar bar = panel.getVerticalScrollBar();
    AdjustmentListener listener = event -> event.getAdjustable().setValue(event.getAdjustable().getMaximum());

    bar.addAdjustmentListener(listener);
    bar.setValueIsAdjusting(true);
    bar.removeAdjustmentListener(listener);
    bar.setValue(bar.getMaximum());
}
 
Example 18
Source File: SmartScroller.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
private void checkScrollBar(AdjustmentEvent e)
{
	//  The scroll bar listModel contains information needed to determine
	//  whether the viewport should be repositioned or not.

	JScrollBar scrollBar = (JScrollBar)e.getSource();
	BoundedRangeModel listModel = scrollBar.getModel();
	int value = listModel.getValue();
	int extent = listModel.getExtent();
	int maximum = listModel.getMaximum();

	boolean valueChanged = previousValue != value;
	boolean maximumChanged = previousMaximum != maximum;

	//  Check if the user has manually repositioned the scrollbar

	if (valueChanged && !maximumChanged)
	{
		if (viewportPosition == START)
			adjustScrollBar = value != 0;
		else
			adjustScrollBar = value + extent >= maximum;
	}

	//  Reset the "value" so we can reposition the viewport and
	//  distinguish between a user scroll and a program scroll.
	//  (ie. valueChanged will be false on a program scroll)

	if (adjustScrollBar && viewportPosition == END)
	{
		//  Scroll the viewport to the end.
		scrollBar.removeAdjustmentListener( this );
		value = maximum - extent;
		scrollBar.setValue( value );
		scrollBar.addAdjustmentListener( this );
	}

	if (adjustScrollBar && viewportPosition == START)
	{
		//  Keep the viewport at the same relative viewportPosition
		scrollBar.removeAdjustmentListener( this );
		value = value + maximum - previousMaximum;
		scrollBar.setValue( value );
		scrollBar.addAdjustmentListener( this );
	}

	previousValue = value;
	previousMaximum = maximum;
}
 
Example 19
Source File: LearnParameters.java    From GpsPrune with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Make the dialog components
 * @return the GUI components for the dialog
 */
private Component makeDialogComponents()
{
	JPanel dialogPanel = new JPanel();
	dialogPanel.setLayout(new BorderLayout());

	// main panel with a box layout
	JPanel mainPanel = new JPanel();
	mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
	// Label at top
	JLabel introLabel = new JLabel(I18nManager.getText("dialog.learnestimationparams.intro") + ":");
	introLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
	introLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
	mainPanel.add(introLabel);

	// Panel for the calculated results
	_calculatedParamPanel = new ParametersPanel("dialog.estimatetime.results", true);
	_calculatedParamPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
	mainPanel.add(_calculatedParamPanel);
	mainPanel.add(Box.createVerticalStrut(14));

	mainPanel.add(new JLabel(I18nManager.getText("dialog.learnestimationparams.combine") + ":"));
	mainPanel.add(Box.createVerticalStrut(4));
	_weightSlider = new JScrollBar(JScrollBar.HORIZONTAL, 5, 1, 0, 11);
	_weightSlider.addAdjustmentListener(new AdjustmentListener() {
		public void adjustmentValueChanged(AdjustmentEvent inEvent)
		{
			if (!inEvent.getValueIsAdjusting()) {
				updateCombinedLabels(calculateCombinedParameters());
			}
		}
	});
	mainPanel.add(_weightSlider);
	_sliderDescLabel = new JLabel(" ");
	_sliderDescLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
	mainPanel.add(_sliderDescLabel);
	mainPanel.add(Box.createVerticalStrut(12));

	// Results panel
	_combinedParamPanel = new ParametersPanel("dialog.learnestimationparams.combinedresults");
	_combinedParamPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
	mainPanel.add(_combinedParamPanel);

	dialogPanel.add(mainPanel, BorderLayout.NORTH);

	// button panel at bottom
	JPanel buttonPanel = new JPanel();
	buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

	// Combine
	_combineButton = new JButton(I18nManager.getText("button.combine"));
	_combineButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent arg0) {
			combineAndFinish();
		}
	});
	buttonPanel.add(_combineButton);

	// Cancel
	JButton cancelButton = new JButton(I18nManager.getText("button.cancel"));
	cancelButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			_dialog.dispose();
		}
	});
	KeyAdapter escapeListener = new KeyAdapter() {
		public void keyPressed(KeyEvent inE) {
			if (inE.getKeyCode() == KeyEvent.VK_ESCAPE) {_dialog.dispose();}
		}
	};
	_combineButton.addKeyListener(escapeListener);
	cancelButton.addKeyListener(escapeListener);
	buttonPanel.add(cancelButton);
	dialogPanel.add(buttonPanel, BorderLayout.SOUTH);
	return dialogPanel;
}
 
Example 20
Source File: LegendView.java    From MeteoInfo with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void initComponents() {
    this.setPreferredSize(new Dimension(100, 200));
    this.setLayout(new BorderLayout());
    this.setBackground(Color.white);

    _vScrollBar = new JScrollBar(JScrollBar.VERTICAL);        
    _vScrollBar.addAdjustmentListener(new AdjustmentListener() {
        @Override
        public void adjustmentValueChanged(AdjustmentEvent e) {
            onScrollValueChanged(e);
        }
    });
    this.add(_vScrollBar, BorderLayout.EAST);
    this._vScrollBar.setSize(20, this.getHeight());
    this._vScrollBar.setLocation(this.getWidth() - this._vScrollBar.getWidth(), 0);        

    _textField = new JTextField();
    _textField.setVisible(false);
    this.add(_textField);

    _frmPointSymbolSet = null;
    _frmPolylineSymbolSet = null;
    _frmPolygonSymbolSet = null;
    _frmColorSymbolSet = null;
    _legendScheme = null;
    _breakHeight = 20;
    _symbolWidth = 60;
    _valueWidth = (this.getWidth() - _symbolWidth) / 2;
    _labelWidth = _valueWidth;
}