Article View: comp.lang.java.gui
Article #87Re: A very humble Java GUI question
From: Jens Gohrke
Date: Fri, 23 Mar 2001 08:07
Date: Fri, 23 Mar 2001 08:07
40 lines
2912 bytes
2912 bytes
Paul King wrote: > I am not necessarily new to Java, but am a novice at writing GUI-based > Java programs. > > ... > > txtMessage.text = "Some text"; > > hoping it would appear as displayed text in the text pane. The logic of > using txtMessage.text is that the "text" part appears as a property on my > CodeWarrior object inspector for the "txtMessage" object. Giving the > "text" property a value in the object inspector results in that value > being displayed. Well, sorry - but "did you hear about beans??". With a bean there might be a property 'text' and access to it is granted using accessor methods 'getText' and/or 'setText'. this is a common pattern to all beans - and Swing components are supposed to be beans, too. No Java style guide misses a phrases stating that the above way (direct access to class members) is to be dropped from coding practices. Well, I don't think that it is that seriously wrong, but you might consider the accessor way - that btw is the way that (almost) every IDE GUI Tool should do it by recommendation. btw. i agree to the other posting by "gbp" about using the getDocument() method for components like JTextPane as JTextPane may encapsulate large text objects - highlighting and other stuff - like Win$ Write.exe... given proper coding ;-) but the text property is not isolated to JTextPane and if you would like to access anything else having a text property (eg. JButton) please stick to the accessor. and also the accessor might hide implementations to update components in the background by calling whatever is necessary to do so. accessing the member directly would need you to do so and thus involve dependencies you might not be aware of --- the saying goes: use accessors where available... Cheers Jens
Technical Details
Message-ID:
<99f01r$fm$01$1@news.t-online.com>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!feeder.qis.net!ptdnetP!newsgate.ptd.net!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.com!t-online.de!news.t-online.com!not-for-mailReferences:
<rihibt42piiu8mbei09uc7o066ll4sramp@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10fd6d,e3664f8ad80898dd X-Google-Attributes: gid10fd6d,public X-Google-Thread: fd047,e3664f8ad80898dd X-Google-Attributes: gidfd047,public X-Google-ArrivalTime: 2001-03-23 00:12:06 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!feeder.qis.net!ptdnetP!newsgate.ptd.net!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.com!t-online.de!news.t-online.com!not-for-mail From: Jens Gohrke <Jens.Gohrke@jSoft.de> Newsgroups: comp.lang.java.gui,codewarrior.windows Subject: Re: A very humble Java GUI question Followup-To: comp.lang.java.gui Date: Fri, 23 Mar 2001 09:07:53 +0100 Organization: jSoft Softwareentwicklungs GmbH Lines: 42 Message-ID: <99f01r$fm$01$1@news.t-online.com> References: <rihibt42piiu8mbei09uc7o066ll4sramp@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 985334652 01 502 KhD42XSZa8BF 010323 08:04:12 X-Complaints-To: abuse@t-online.com X-Sender: 520057915985-0001@t-dialin.net User-Agent: KNode/0.4