PDA

View Full Version : fill a JList


Karlien
02-19-04, 02:54 PM
A hava a problem with filling my JList. I put my data that I gain from a database in an array. Then I want to put this data in my list but my list refuses to display my data.
With this code I fill my array:

strSql="select * from ict10_opties";
resOpties = stmVermelding.executeQuery(strSql);
resOpties.last();
intOptiesAantal=resOpties.getRow();
arrOpties=new String[intOptiesAantal];
resOpties.first();
int i=0;
arrOpties[i]=String.valueOf(resOpties.getInt(1));
while(resOpties.next())
{
i=i+1;
arrOpties[i]=String.valueOf(resOpties.getInt(1));
}

And with this code I would like to put my array in my list:
lstOptie=new JList(arrOpties);

Can anyone help me??

Thank You

stdunbar
02-19-04, 03:30 PM
A hava a problem with filling my JList. I put my data that I gain from a database in an array. Then I want to put this data in my list but my list refuses to display my data.
With this code I fill my array:

strSql="select * from ict10_opties";
resOpties = stmVermelding.executeQuery(strSql);
resOpties.last();
intOptiesAantal=resOpties.getRow();
arrOpties=new String[intOptiesAantal];
resOpties.first();
int i=0;
arrOpties[i]=String.valueOf(resOpties.getInt(1));
while(resOpties.next())
{
i=i+1;
arrOpties[i]=String.valueOf(resOpties.getInt(1));
}

And with this code I would like to put my array in my list:
lstOptie=new JList(arrOpties);

Can anyone help me??

Thank You


Are you sure that the JDBC code is working the way you want? In your loop if you print out the values from the ResultSet are they what you expect? It looks to me like your code, while unique, should basically work the way you want assuming you are working on a JDBC driver and database that properly support cursors.

Ella
03-02-04, 10:06 AM
Is your list in a scroll pane?

For example:


public class Dialog1 extends JDialog {
private JScrollPane jScrollPane1 = null;
private JList jList1 = new JList(new String[]{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o"} );

public Dialog1() throws HeadlessException
{
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception
{
jScrollPane1 = new JScrollPane(jList1);
this.getContentPane().setLayout(null);
jScrollPane1.setBounds(new Rectangle(34, 82, 279, 114));

this.getContentPane().add(jScrollPane1, null);
jScrollPane1.getViewport().add(jList1);
}
}