Re: JList display problem

From: Will (will_at_coderight.nl)
Date: 05/10/04


Date: 10 May 2004 01:22:31 -0700

See changes i made in your code.
Just a quick one NOT tested but should give you
an idea how to do it...

Even better would be to use SwingWorker in this case.

Will
www.coderight.nl

cmills28@yahoo.com (ChrisM) wrote in message news:<f7488ad.0405091715.73f03333@posting.google.com>...
> I am using a JList with a DefaultListModel. Most of the time, when I
> add elements to the model, the JList will display them ok. But once
> in a while, it doesn't. It'll display no elements I just added, but
> it acts like there's data being displayed (scrollbars will appear -
> the JList is inside a JScrollPane). From the debugger, the
> defaultlistmodel does contain the correct data (Strings), but it's not
> displayed in the JList. I've tried several suggestions I've seen,
> like calling paint(), repaint(), validate(), but all fail to correct
> the problem. A code snippet is below. What am I doing wrong? Or is
> this a bug in JList? Thanks!!
>
> class MainGUI {
> JButton button = new JButton();
> JList listBox = new JList();
> DefaultListModel dlm = new DefaultListModel();
>
> listBox.setModel(dlm);
>
> // this button to update the JList
> button_actionPerformed(ActionEvent e) {
> MyThread t = new MyThread(listBox);

         SwingUtilities.invokeLater(t);
> }
> }
>
> class MyThread implements Runnable {
> JList list;
>
> MyThread(JList list) {
> this.list = list;
> }
>
> public void run() {
> // here is where I do all the data processing.
> // When done, I put the results into the JList's model
>
> for(int i=0; i<num; i++) { // num is the # of data elements to
> add to
> //the list
> String data = (whatever);
           ((DefaultListModel) list.getModel()).addElement(data);
> }
> }
> }



Relevant Pages

  • JList display problem
    ... I am using a JList with a DefaultListModel. ... the JList will display them ok. ... defaultlistmodel does contain the correct data, ... class MainGUI { ...
    (comp.lang.java.gui)
  • RE: Combo Box Does Not Display Value
    ... Ken's answer tells you how to get the list current, not why the booth number ... text box will display the correct data on the other records. ... "down arrow" button, tough! ...
    (microsoft.public.access.forms)
  • mailmerge with word 2002 and access
    ... In the previous version of word the merged fields ... all show the correct data but in word 2002 the data ... displays £11.00 with the switches and 10.1 without. ... amounts display correctly in the same field. ...
    (microsoft.public.word.mailmerge.fields)
  • cannot change value of texbox w/in datagrid after first bind
    ... I have a datagrid with the columns defined in the aspx ... I have other bound columns that display the correct data so I know the dataset is ok. ...
    (microsoft.public.dotnet.framework.aspnet.datagridcontrol)
  • cannot change value of texbox w/in datagrid after first bind
    ... I have a datagrid with the columns defined in the aspx ... I have other bound columns that display the correct data so I know the dataset is ok. ...
    (microsoft.public.dotnet.languages.vb)