Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #13794

Re: swing component?

Path csiph.com!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail
From Jan Burse <janburse@fastmail.fm>
Newsgroups comp.lang.java.programmer
Subject Re: swing component?
Date Sun, 22 Apr 2012 17:18:26 +0200
Organization albasani.net
Lines 63
Message-ID <jn17g2$agj$1@news.albasani.net> (permalink)
References <24010092.561.1335104359317.JavaMail.geo-discussion-forums@pbckz3> <jn175o$9u8$1@news.albasani.net>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.albasani.net uLhqlFt8TDLQh6rNvrGhATOfNLNBjdtNEf2z8bTVtjRe2OJDl6LFP1R2kHSi90f1CALciHo/5XiOoNugf3ZLyjcWe7PBCPLUp2Tds3+sam6XRPUlYw9AlCzoscGaD6O4
NNTP-Posting-Date Sun, 22 Apr 2012 15:18:26 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="Ro8pZgLliia8EVgleDky7v8Hqay/QEiLBuorjdFKhf4Q2KN7tqeBqN07LP6nWD42GyVI7yrBBHas38vcbAcQet49Lut1hqGnoHntQdfPI1W/UuuW5jDcs3jZ62yVba9c"; mail-complaints-to="abuse@albasani.net"
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:11.0) Gecko/20120312 Firefox/11.0 SeaMonkey/2.8
In-Reply-To <jn175o$9u8$1@news.albasani.net>
Cancel-Lock sha1:Tr0B9XSEutV3p55LcRG5AtYat3M=
Xref csiph.com comp.lang.java.programmer:13794

Show key headers only | View raw


Jan Burse schrieb:
> Peter Cheung schrieb:
>> Hi All, does swing component provide something like:
>>
>> component.setProperty("whatever", "value"); ??
>>
>> thanks
>> from Peter (cmk128@hotmail.com)
>
> Hi,
>
> You can attach client data to a Swing component.
> The methods are:
>
> public class JComponent {
>
> /**
> * Adds an arbitrary key/value "client property" to this component.
> */
> public void putClientProperty(Object key, Object value);
>
> /**
> * Returns the value of the property with the specified key.
> */
> public Object getClientProperty(Object key);
>
> }
>
>
> But you must assure that the key does not clash
> with a key already used internally by Swing.
> Easiest is to use a key that resembles in the prefix
> one of your package names.
>
> For example:
>
> myTable.putClientProperty("com.mycompany.mypackage.mykey", "value");
>
> Bye
>

The javadoc says:

"The clientProperty dictionary is not intended to support large scale 
extensions to JComponent nor should be it considered an alternative to 
subclassing when designing a new component."

So an alternative route would be to subclass:

     class myTable extends JTable {
         myType myKey;
     }

Advantage is a little bit more type safety. Since the new field
has now a type. So the compiler can do his work when you assign
values, and spot errors or do box/unboxing etc..

But subclassing might not always be possible, for example when
foreign code is used, and some static factory method
irrevocable creates the GUI component. So client data is then
a valid resort.

Bye

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

swing component? Peter Cheung <cmk128@gmail.com> - 2012-04-22 07:19 -0700
  Re: swing component? markspace <-@.> - 2012-04-22 07:47 -0700
  Re: swing component? "Qu0ll" <Qu0llSixFour@gmail.com> - 2012-04-23 01:05 +1000
  Re: swing component? Jan Burse <janburse@fastmail.fm> - 2012-04-22 17:12 +0200
    Re: swing component? Jan Burse <janburse@fastmail.fm> - 2012-04-22 17:18 +0200
      Re: swing component? markspace <-@.> - 2012-04-22 10:10 -0700
        Re: swing component? Peter <mcheung63@gmail.com> - 2012-04-24 06:44 -0700
      Re: swing component? Roedy Green <see_website@mindprod.com.invalid> - 2012-04-27 05:06 -0700
  Re: swing component? Roedy Green <see_website@mindprod.com.invalid> - 2012-04-24 08:52 -0700

csiph-web