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


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

Re: JComboBox with IDentifiers

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit3.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!53ab2750!not-for-mail
From "Daniele Futtorovic" <daniele.futtorovic@1:261/38.remove-nlb-this>
Subject Re: JComboBox with IDentifiers
Message-ID <502943B8.56783.calajapr@time.synchro.net> (permalink)
X-Comment-To Sax@DIST
Newsgroups comp.lang.java.programmer
In-Reply-To <502943B7.56779.calajapr@time.synchro.net>
References <502943B7.56779.calajapr@time.synchro.net>
X-FTN-AREA COMP.LANG.JAVA.PROGRAMMER
X-FTN-MSGID 1:261/38 d3342816
X-FTN-REPLY 1:261/38 c971fe37
Content-Type text/plain; charset=IBM437
Content-Transfer-Encoding 8bit
X-Gateway time.synchro.net [Synchronet 3.16a-Win32 NewsLink 1.98]
Lines 51
Date Mon, 13 Aug 2012 18:36:23 GMT
NNTP-Posting-Host 69.21.70.65
X-Complaints-To news@tds.net
X-Trace newsreading01.news.tds.net 1344882983 69.21.70.65 (Mon, 13 Aug 2012 13:36:23 CDT)
NNTP-Posting-Date Mon, 13 Aug 2012 13:36:23 CDT
Organization tds.net
Xref csiph.com comp.lang.java.programmer:17835

Show key headers only | View raw


  To: Sax@DIST
From: Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid>

On 13/08/2012 18:22, Sax@DIST allegedly wrote:
> Hi markspace,
>  thanks a lot for the two links you suggested me about the Java Programming
Language!   0;-)
>
> The first one, about the "correct" usage of JComboBox itself, is very
detailed and I think I can find what I need, reading the lots of examples.
>
> The second one, about the database connection, will be very useful for me, as
I need to get the data for the items of my JComboBox from a DataBase Table.
>
> After all, my needs are very simple:
> (o) to read some records (fields required: 'IDentifier' and 'Description')
from a DB-Table
> (o) to show the 'Description' of the records as Items of the JComboBox
> (o) to do something else with the 'IDentifier' of the selected Item within
the JComboBox
>
> Thanks again for your precious help,
>  Greetings.
>   Roberto
>    08-)

Hi Roberto,

You should create a custom data structure containing the data you need 
(identifier and representation, from the looks of it), add them to the 
JComboBox's contents, and use a custom renderer 
(<http://docs.oracle.com/javase/6/docs/api/javax/swing/JComboBox.html#setRender
er(javax.swing.ListCellRenderer)>).
That way, the _items_ in the combo box will always be your custom data 
structure instances (which you can use in #setSelectedItem(Object), for 
instance; or returned by #getSelectedItem()), and the renderer controls how 
they're displayed.

In addition -- I believe I've already seen something like this coded somewhere 
-- you can write your own custom model (<http://docs.oracle.com/javase/6/docs/api/javax/swing/ComboBoxModel.html>)
and have that hook directly to the database, possibly with on-demand, 
lightweight loading of data.

HTH,
--
DF.

--- BBBS/Li6 v4.10 Dada-1
 * Origin: Prism bbs (1:261/38)
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

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


Thread

Re: JComboBox with IDentifiers Sax@DIST.remove-nlb-this - 2012-08-13 18:36 +0000
  Re: JComboBox with IDentifiers "markspace" <markspace@1:261/38.remove-nlb-this> - 2012-08-13 18:36 +0000
    Re: JComboBox with IDentifiers Sax@DIST.remove-nlb-this - 2012-08-13 18:36 +0000
      Re: JComboBox with IDentifiers "Daniele Futtorovic" <daniele.futtorovic@1:261/38.remove-nlb-this> - 2012-08-13 18:36 +0000

csiph-web