Showing JList in a JPanel
Hey!
I'm currently making my very first GUI-application, and I need some help. I'm connecting my app to a local mySQL database on my laptop, and I'm having some problems displaying the results from a query made on the database.
Code:
rs = stmt.executeQuery( "SELECT * FROM " +tingType+" WHERE navn='" +navn+ "'" );
while(rs.next()) {
resultat.add(rs.getString("navn"));
resultat.add(rs.getString("BruktSist"));
resultat.add(rs.getString("lagringsPlass"));
}
Resultat is an ArrayList which I have defined earlier in the code. Now, the real problem is that when I try to display these results using a JList in a JPanel nothing gets display in the JFrame!
Code:
public class Resultat extends JPanel{
private static final long serialVersionUID = 1L;
private JList resultatListe;
public Resultat(ArrayList<String> resultSet) {
GridBagLayout gridBag = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
setLayout(gridBag);
JLabel resultat = new JLabel("Resultat:");
resultatListe = new JList((ListModel) resultSet);
gbc.ipadx = 10;
gbc.insets = new Insets(5,5,5,5);
gbc.anchor = GridBagConstraints.WEST;
gbc.gridx = 0;
gbc.gridy = 0;
add(resultat, gbc);
gbc.gridy = 1;
add(resultatListe, gbc);
}
If someone could tell me if I'm doing something wrong in displaying the JList in the JPanel, that would be awesome! :D
Thanks in advance.