/ Forside / Teknologi / Udvikling / Java / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
Java
#NavnPoint
molokyle 3688
Klaudi 855
strarup 740
Forvirret 660
gøgeungen 500
Teil 373
Stouenberg 360
vnc 360
pmbruun 341
10  mccracken 320
JComboBox refresh(not to addElement) but w~
Fra : Roma Chan


Dato : 28-09-02 20:05

Hi all, I stucked by following recently:

----------------------------------------------------------------------------
------------------
I use JComboBox to display retrieved data (in form of Vector) in database,

databaseVector = database.getVector();
JComboBox jcbInstance = new JComboBox(dataBaseVector);

but after database content changed, I do:

databaseVector = newVectorValue;
jcbInstance.revalidate();
jcbInstance.repaint();

----------------------------------------------------------------------------
---------------
Then I find that the ComboBox just display something old, not refreshing
stuff.

Could anyone help me with this? Thank you and welcome any suggestion.

Chan



 
 
Carsten Højgaard (28-09-2002)
Kommentar
Fra : Carsten Højgaard


Dato : 28-09-02 20:22

> I use JComboBox to display retrieved data (in form of Vector) in database,
>
> databaseVector = database.getVector();
> JComboBox jcbInstance = new JComboBox(dataBaseVector);
>
> but after database content changed, I do:
>
> databaseVector = newVectorValue;
> jcbInstance.revalidate();
> jcbInstance.repaint();
>
> --------------------------------------------------------------------------
--
> ---------------
> Then I find that the ComboBox just display something old, not refreshing
> stuff.
>
> Could anyone help me with this? Thank you and welcome any suggestion.

Hi Chan,

This works for me. It's probaly not the best solution... but it works

jcbInstance.removeAllItems();
for (int i = 0; i < databaseVector .size(); i++)
jcbInstance.addItem(databaseVector .get(i));




Roma Chan (28-09-2002)
Kommentar
Fra : Roma Chan


Dato : 28-09-02 21:03

Yeah! Carsten. You are right, I am too stubborn, to a point that attempt in
implementing ListDataListener, thinking contentschanged method may helps...I
used yours suggestion now....Very much thanks......

But by the way, I haven't use revalidate and repaint, it works already, is
it OK? not to do repaint/revalidate.

^_- Thanks
Chan

"Carsten Højgaard" <nospam_carsten@hojgard.dk> ¼¶¼g©ó¶l¥ó·s»D
:3d9601b3$0$18147$edfadb0f@dspool01.news.tele.dk...
> > I use JComboBox to display retrieved data (in form of Vector) in
database,
> >
> > databaseVector = database.getVector();
> > JComboBox jcbInstance = new JComboBox(dataBaseVector);
> >
> > but after database content changed, I do:
> >
> > databaseVector = newVectorValue;
> > jcbInstance.revalidate();
> > jcbInstance.repaint();
> >
>
> --------------------------------------------------------------------------
> --
> > ---------------
> > Then I find that the ComboBox just display something old, not refreshing
> > stuff.
> >
> > Could anyone help me with this? Thank you and welcome any suggestion.
>
> Hi Chan,
>
> This works for me. It's probaly not the best solution... but it works
>
> jcbInstance.removeAllItems();
> for (int i = 0; i < databaseVector .size(); i++)
> jcbInstance.addItem(databaseVector .get(i));
>
>
>



Anders K. Olsen (28-09-2002)
Kommentar
Fra : Anders K. Olsen


Dato : 28-09-02 21:40

"Roma Chan" <romachan@netvigator.com> skrev i en meddelelse
news:an4ufr$k2m2@imsp212.netvigator.com...
> Hi all, I stucked by following recently:
>
> --------------------------------------------------------------------------
--
> ------------------
> I use JComboBox to display retrieved data (in form of Vector) in database,
>
> databaseVector = database.getVector();

Here you have an attribute which value is a reference to a Vector (VectorA).

> JComboBox jcbInstance = new JComboBox(dataBaseVector);

Now some internal attribute of jcbInstance has a value that is a reference
to VectorA. That is, the internal value is a copy of the value held by
databaseVector.

>
> but after database content changed, I do:
>
> databaseVector = newVectorValue;

Now you have updated the value of the databaseVector attribute, but you
haven't updated the value of the internal reference in jcbInstance.

> jcbInstance.revalidate();
> jcbInstance.repaint();
>
> --------------------------------------------------------------------------
--
> ---------------
> Then I find that the ComboBox just display something old, not refreshing
> stuff.

That is because you haven´t updated the internal reference in jcbInstance.

> Could anyone help me with this? Thank you and welcome any suggestion.

I don't know much about JComboBox, so I don't know what options that API
gives you, but you basically have two options:

1) You can change the contents of the Vector reference (that is, call
methods on the object, not change the reference), and hope that this change
will cause the JComboBox to change its display. But that will mean that you
rely on some internal mechanism of JComboBox that you basically have no
control over. Eg. if JComboBox takes a copy of all the elements in the
Vector and store them in some internal format, you may have no way of
changing (and no reason to change) this internal format.

2) You can give the new Vector to jcbInstance (if that is possible) and ask
the jcbInstance to repaint it self based on this new Vector. I would prefere
this method, because that doesn't rely on some internal mechanism of
JComboBox.

Hope this helps.

/Anders



Søg
Reklame
Statistik
Spørgsmål : 177552
Tips : 31968
Nyheder : 719565
Indlæg : 6408847
Brugere : 218887

Månedens bedste
Årets bedste
Sidste års bedste