下面列出了怎么用java.awt.event.AdjustmentListener的API类实例代码及写法,或者点击链接到github查看源代码。
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);
}
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;
}
private void initUI()
{
setLayout(new MigLayout("", "[]", "[]"));
add(Box.createRigidArea(new Dimension(width, height)), "cell 0 0,alignx left,aligny top");
setBackground(Color.DARK_GRAY);
palette = new ArrayList<Color>();
palette.add(new Color(255, 0, 0));
palette.add(new Color(0, 255, 0));
palette.add(new Color(0, 0, 255));
scrollBar = new JScrollBar(JScrollBar.HORIZONTAL);
scrollBar.setUI(new ModernScrollBarUI());
scrollBar.setPreferredSize(new Dimension(width, 20));
scrollBar.setMaximum(11);
scrollBar.setMinimum(0);
scrollBar.setValue(0);
scrollBar.setVisible(false);
scrollBar.addAdjustmentListener(new AdjustmentListener()
{
@Override
public void adjustmentValueChanged(AdjustmentEvent e)
{
repaint();
}
});
add(scrollBar, "cell 0 1");
addMouseListener(new MouseHandler());
}
private void hookScrollBarValueChange() {
scrollBar.addAdjustmentListener(new AdjustmentListener() {
public void adjustmentValueChanged(final AdjustmentEvent e) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
treeTable.setTreeCellOffsetX(e.getValue());
if (!e.getValueIsAdjusting()) updateScrollBar(false);
}
});
}
});
}
@Override
protected JComponent getSwingComponent() {
JScrollBar ch = new JScrollBar(JScrollBar.VERTICAL);
ch.setPreferredSize(new Dimension(50, 50));
ch.setValue(50);
ch.addAdjustmentListener(new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent e) {
wasLWClicked = true;
}
});
OverlappingTestBase.shift = new Point(20, 16);
return ch;
}
@Override
protected JComponent getSwingComponent() {
JScrollBar ch = new JScrollBar(JScrollBar.VERTICAL);
ch.setPreferredSize(new Dimension(50, 50));
ch.setValue(50);
ch.addAdjustmentListener(new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent e) {
wasLWClicked = true;
}
});
OverlappingTestBase.shift = new Point(20, 16);
return ch;
}
/**
* Maps {@code Scrollbar.addAdjustmentListener(AdjustmentListener)}
* through queue
*/
public void addAdjustmentListener(final AdjustmentListener adjustmentListener) {
runMapping(new MapVoidAction("addAdjustmentListener") {
@Override
public void map() {
((Scrollbar) getSource()).addAdjustmentListener(adjustmentListener);
}
});
}
/**
* Maps {@code Scrollbar.removeAdjustmentListener(AdjustmentListener)}
* through queue
*/
public void removeAdjustmentListener(final AdjustmentListener adjustmentListener) {
runMapping(new MapVoidAction("removeAdjustmentListener") {
@Override
public void map() {
((Scrollbar) getSource()).removeAdjustmentListener(adjustmentListener);
}
});
}
/**
* Maps {@code JScrollBar.addAdjustmentListener(AdjustmentListener)}
* through queue
*/
public void addAdjustmentListener(final AdjustmentListener adjustmentListener) {
runMapping(new MapVoidAction("addAdjustmentListener") {
@Override
public void map() {
((JScrollBar) getSource()).addAdjustmentListener(adjustmentListener);
}
});
}
/**
* Maps {@code JScrollBar.removeAdjustmentListener(AdjustmentListener)}
* through queue
*/
public void removeAdjustmentListener(final AdjustmentListener adjustmentListener) {
runMapping(new MapVoidAction("removeAdjustmentListener") {
@Override
public void map() {
((JScrollBar) getSource()).removeAdjustmentListener(adjustmentListener);
}
});
}
@Override
public void addAdjustmentListener(AdjustmentListener l) {
delegate.addAdjustmentListener(l);
}
@Override
public AdjustmentListener[] getAdjustmentListeners() {
return delegate.getAdjustmentListeners();
}
@Override
public void removeAdjustmentListener(AdjustmentListener l) {
delegate.removeAdjustmentListener(l);
}
/** Creates new form DebuggingView */
public DebuggingViewComponent() {
setIcon(ImageUtilities.loadImage ("org/netbeans/modules/debugger/resources/debuggingView/debugging_16.png")); // NOI18N
// Remember the location of the component when closed.
putClientProperty("KeepNonPersistentTCInModelWhenClosed", Boolean.TRUE); // NOI18N
initComponents();
resumeIcon = ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/debuggingView/resume_button_16.png", false);
focusedResumeIcon = ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/debuggingView/resume_button_focused_16.png", false);
pressedResumeIcon = ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/debuggingView/resume_button_pressed_16.png", false);
suspendIcon = ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/debuggingView/suspend_button_16.png", false);
focusedSuspendIcon = ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/debuggingView/suspend_button_focused_16.png", false);
pressedSuspendIcon = ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/debuggingView/suspend_button_pressed_16.png", false);
setBackground(treeBackgroundColor);
leftPanel = new BarsPanel();
rightPanel = new IconsPanel();
mainPanel.setBackground(treeBackgroundColor);
mainPanel.add(leftPanel, BorderLayout.WEST);
mainPanel.add(rightPanel, BorderLayout.EAST);
tapPanel = new TapPanel();
tapPanel.setOrientation(TapPanel.DOWN);
tapPanel.setExpanded(true);
infoPanel = new InfoPanel(tapPanel, this);
tapPanel.add(infoPanel);
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
add(tapPanel, gridBagConstraints);
manager.addPropertyChangeListener(this);
prefListener = new DebuggingPreferenceChangeListener();
preferences.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, prefListener, preferences));
sessionsComboListener = new SessionsComboBoxListener();
scrollBarPanel.setVisible(false);
if( "Aqua".equals(UIManager.getLookAndFeel().getID()) ) { //NOI18N
scrollBarPanel.setBackground(tapPanel.getBackground());
scrollBarPanel.setOpaque(true);
}
treeScrollBar.addAdjustmentListener(this);
setSuspendTableVisible(preferences.getBoolean(FiltersDescriptor.SHOW_SUSPEND_TABLE, true));
mainScrollPane.getVerticalScrollBar().addAdjustmentListener(
new AdjustmentListener() {
@Override
public void adjustmentValueChanged(AdjustmentEvent e) {
if (!e.getValueIsAdjusting() && !ignoreScrollAdjustment) {
storeScrollPosition();
}
}
});
}
/**
* Adds the specified adjustment listener to receive adjustment
* events from this <code>ScrollPaneAdjustable</code>.
* If <code>l</code> is <code>null</code>, no exception is thrown
* and no action is performed.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param l the adjustment listener.
* @see #removeAdjustmentListener
* @see #getAdjustmentListeners
* @see java.awt.event.AdjustmentListener
* @see java.awt.event.AdjustmentEvent
*/
public synchronized void addAdjustmentListener(AdjustmentListener l) {
if (l == null) {
return;
}
adjustmentListener = AWTEventMulticaster.add(adjustmentListener, l);
}
/**
* Removes the specified adjustment listener so that it no longer
* receives adjustment events from this <code>ScrollPaneAdjustable</code>.
* If <code>l</code> is <code>null</code>, no exception is thrown
* and no action is performed.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param l the adjustment listener.
* @see #addAdjustmentListener
* @see #getAdjustmentListeners
* @see java.awt.event.AdjustmentListener
* @see java.awt.event.AdjustmentEvent
* @since JDK1.1
*/
public synchronized void removeAdjustmentListener(AdjustmentListener l){
if (l == null) {
return;
}
adjustmentListener = AWTEventMulticaster.remove(adjustmentListener, l);
}
/**
* Adds the specified adjustment listener to receive adjustment
* events from this <code>ScrollPaneAdjustable</code>.
* If <code>l</code> is <code>null</code>, no exception is thrown
* and no action is performed.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param l the adjustment listener.
* @see #removeAdjustmentListener
* @see #getAdjustmentListeners
* @see java.awt.event.AdjustmentListener
* @see java.awt.event.AdjustmentEvent
*/
public synchronized void addAdjustmentListener(AdjustmentListener l) {
if (l == null) {
return;
}
adjustmentListener = AWTEventMulticaster.add(adjustmentListener, l);
}
/**
* Removes the specified adjustment listener so that it no longer
* receives adjustment events from this <code>ScrollPaneAdjustable</code>.
* If <code>l</code> is <code>null</code>, no exception is thrown
* and no action is performed.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param l the adjustment listener.
* @see #addAdjustmentListener
* @see #getAdjustmentListeners
* @see java.awt.event.AdjustmentListener
* @see java.awt.event.AdjustmentEvent
* @since JDK1.1
*/
public synchronized void removeAdjustmentListener(AdjustmentListener l){
if (l == null) {
return;
}
adjustmentListener = AWTEventMulticaster.remove(adjustmentListener, l);
}
/**
* Removes the specified adjustment listener so that it no longer
* receives adjustment events from this <code>ScrollPaneAdjustable</code>.
* If <code>l</code> is <code>null</code>, no exception is thrown
* and no action is performed.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param l the adjustment listener.
* @see #addAdjustmentListener
* @see #getAdjustmentListeners
* @see java.awt.event.AdjustmentListener
* @see java.awt.event.AdjustmentEvent
* @since JDK1.1
*/
public synchronized void removeAdjustmentListener(AdjustmentListener l){
if (l == null) {
return;
}
adjustmentListener = AWTEventMulticaster.remove(adjustmentListener, l);
}
/**
* Adds the specified adjustment listener to receive adjustment
* events from this <code>ScrollPaneAdjustable</code>.
* If <code>l</code> is <code>null</code>, no exception is thrown
* and no action is performed.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param l the adjustment listener.
* @see #removeAdjustmentListener
* @see #getAdjustmentListeners
* @see java.awt.event.AdjustmentListener
* @see java.awt.event.AdjustmentEvent
*/
public synchronized void addAdjustmentListener(AdjustmentListener l) {
if (l == null) {
return;
}
adjustmentListener = AWTEventMulticaster.add(adjustmentListener, l);
}
/**
* Removes the specified adjustment listener so that it no longer
* receives adjustment events from this <code>ScrollPaneAdjustable</code>.
* If <code>l</code> is <code>null</code>, no exception is thrown
* and no action is performed.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param l the adjustment listener.
* @see #addAdjustmentListener
* @see #getAdjustmentListeners
* @see java.awt.event.AdjustmentListener
* @see java.awt.event.AdjustmentEvent
* @since JDK1.1
*/
public synchronized void removeAdjustmentListener(AdjustmentListener l){
if (l == null) {
return;
}
adjustmentListener = AWTEventMulticaster.remove(adjustmentListener, l);
}
/**
* Adds the specified adjustment listener to receive adjustment
* events from this <code>ScrollPaneAdjustable</code>.
* If <code>l</code> is <code>null</code>, no exception is thrown
* and no action is performed.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param l the adjustment listener.
* @see #removeAdjustmentListener
* @see #getAdjustmentListeners
* @see java.awt.event.AdjustmentListener
* @see java.awt.event.AdjustmentEvent
*/
public synchronized void addAdjustmentListener(AdjustmentListener l) {
if (l == null) {
return;
}
adjustmentListener = AWTEventMulticaster.add(adjustmentListener, l);
}
/**
* Removes the specified adjustment listener so that it no longer
* receives adjustment events from this <code>ScrollPaneAdjustable</code>.
* If <code>l</code> is <code>null</code>, no exception is thrown
* and no action is performed.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param l the adjustment listener.
* @see #addAdjustmentListener
* @see #getAdjustmentListeners
* @see java.awt.event.AdjustmentListener
* @see java.awt.event.AdjustmentEvent
* @since JDK1.1
*/
public synchronized void removeAdjustmentListener(AdjustmentListener l){
if (l == null) {
return;
}
adjustmentListener = AWTEventMulticaster.remove(adjustmentListener, l);
}
/**
* Adds the specified adjustment listener to receive adjustment
* events from this <code>ScrollPaneAdjustable</code>.
* If <code>l</code> is <code>null</code>, no exception is thrown
* and no action is performed.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param l the adjustment listener.
* @see #removeAdjustmentListener
* @see #getAdjustmentListeners
* @see java.awt.event.AdjustmentListener
* @see java.awt.event.AdjustmentEvent
*/
public synchronized void addAdjustmentListener(AdjustmentListener l) {
if (l == null) {
return;
}
adjustmentListener = AWTEventMulticaster.add(adjustmentListener, l);
}
/**
* Removes the specified adjustment listener so that it no longer
* receives adjustment events from this <code>ScrollPaneAdjustable</code>.
* If <code>l</code> is <code>null</code>, no exception is thrown
* and no action is performed.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param l the adjustment listener.
* @see #addAdjustmentListener
* @see #getAdjustmentListeners
* @see java.awt.event.AdjustmentListener
* @see java.awt.event.AdjustmentEvent
* @since JDK1.1
*/
public synchronized void removeAdjustmentListener(AdjustmentListener l){
if (l == null) {
return;
}
adjustmentListener = AWTEventMulticaster.remove(adjustmentListener, l);
}
/**
* Adds the specified adjustment listener to receive adjustment
* events from this <code>ScrollPaneAdjustable</code>.
* If <code>l</code> is <code>null</code>, no exception is thrown
* and no action is performed.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param l the adjustment listener.
* @see #removeAdjustmentListener
* @see #getAdjustmentListeners
* @see java.awt.event.AdjustmentListener
* @see java.awt.event.AdjustmentEvent
*/
public synchronized void addAdjustmentListener(AdjustmentListener l) {
if (l == null) {
return;
}
adjustmentListener = AWTEventMulticaster.add(adjustmentListener, l);
}
/**
* Removes the specified adjustment listener so that it no longer
* receives adjustment events from this <code>ScrollPaneAdjustable</code>.
* If <code>l</code> is <code>null</code>, no exception is thrown
* and no action is performed.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param l the adjustment listener.
* @see #addAdjustmentListener
* @see #getAdjustmentListeners
* @see java.awt.event.AdjustmentListener
* @see java.awt.event.AdjustmentEvent
* @since JDK1.1
*/
public synchronized void removeAdjustmentListener(AdjustmentListener l){
if (l == null) {
return;
}
adjustmentListener = AWTEventMulticaster.remove(adjustmentListener, l);
}
/**
* Adds the specified adjustment listener to receive adjustment
* events from this {@code ScrollPaneAdjustable}.
* If {@code l} is {@code null}, no exception is thrown
* and no action is performed.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param l the adjustment listener.
* @see #removeAdjustmentListener
* @see #getAdjustmentListeners
* @see java.awt.event.AdjustmentListener
* @see java.awt.event.AdjustmentEvent
*/
public synchronized void addAdjustmentListener(AdjustmentListener l) {
if (l == null) {
return;
}
adjustmentListener = AWTEventMulticaster.add(adjustmentListener, l);
}
/**
* Removes the specified adjustment listener so that it no longer
* receives adjustment events from this {@code ScrollPaneAdjustable}.
* If {@code l} is {@code null}, no exception is thrown
* and no action is performed.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param l the adjustment listener.
* @see #addAdjustmentListener
* @see #getAdjustmentListeners
* @see java.awt.event.AdjustmentListener
* @see java.awt.event.AdjustmentEvent
* @since 1.1
*/
public synchronized void removeAdjustmentListener(AdjustmentListener l){
if (l == null) {
return;
}
adjustmentListener = AWTEventMulticaster.remove(adjustmentListener, l);
}
/**
* Adds the specified adjustment listener to receive adjustment
* events from this {@code ScrollPaneAdjustable}.
* If {@code l} is {@code null}, no exception is thrown
* and no action is performed.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model.
*
* @param l the adjustment listener.
* @see #removeAdjustmentListener
* @see #getAdjustmentListeners
* @see java.awt.event.AdjustmentListener
* @see java.awt.event.AdjustmentEvent
*/
public synchronized void addAdjustmentListener(AdjustmentListener l) {
if (l == null) {
return;
}
adjustmentListener = AWTEventMulticaster.add(adjustmentListener, l);
}