Re: JList display problem
From: Will (will_at_coderight.nl)
Date: 05/10/04
- Next message: Andrew Thompson: "Re: Swing units"
- Previous message: Abs: "Re: Swing units"
- In reply to: ChrisM: "JList display problem"
- Next in thread: ChrisM: "Re: JList display problem"
- Reply: ChrisM: "Re: JList display problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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);
> }
> }
> }
- Next message: Andrew Thompson: "Re: Swing units"
- Previous message: Abs: "Re: Swing units"
- In reply to: ChrisM: "JList display problem"
- Next in thread: ChrisM: "Re: JList display problem"
- Reply: ChrisM: "Re: JList display problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|