Article View: borland.public.jbuilder.java.swing
Article #12543Swing Event Processing
From: Wayne Cole
Date: Mon, 21 Dec 1998 00:00
Date: Mon, 21 Dec 1998 00:00
37 lines
2151 bytes
2151 bytes
I took a little AWT 1.1.7 application and converted it to Swing 1.0.3 - boy what a difference in event generation! It seems that an AWT component will only generate an event when the user manipulates the component. Swing, OTOH, will generate an event when any change is made to the component's underlying data model whether the change was made programmatically or by a user's manipulation of the component. For example, under AWT if you have two color controls consisting of a slider and textfield for each color component (R,G, and B for one control and H, S, and V for the other) and the user manipulates the R slider, that event can be listened for and use to update the HSV control so that it shows the HSV equivalent of the new RGB color. All that is required is to add the adjustment listener to the slider. Under Swing, using a JSlider, the only listener you have at your disposal is the change listener. It generates events if the value, min, max or extent of the JSlider is changed regardless of whether a user initiates it or the other color control is causing the calculated new color values to be set into the controls that were not manipulated. Due to round-off errors in the conversion between RGB and HSV, the control update events echo back and forth for up to 20 minutes! So far, the only way I've found to defeat the echoing is to remove the listener from the control I need to programmatically update, set the new values into that control, then re-add the change listener back to these controls. My question: is this "kosher Java" or is there some other simple way to restrict a control's event generation to only occur when the component is manipulated by a user? -- wmc
Technical Details
Message-ID:
<MPG.10e85069f5fc58b798968d@forums.inprise.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,90489898f45b5c09,start X-Google-Attributes: gid111d45,public From: wmcole@ihpweb.com (Wayne Cole) Subject: Swing Event Processing Date: 1998/12/21 Message-ID: <MPG.10e85069f5fc58b798968d@forums.inprise.com> X-Deja-AN: 424605668 Organization: Infinity Heart Productions Newsgroups: borland.public.jbuilder.java.swing