Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8010915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:52:42+00:00 2026-06-04T18:52:42+00:00

I am trying to fill a JList with some data that I get from

  • 0

I am trying to fill a JList with some data that I get from a DB, for the purpose I first put the data into a vector and then I call the JList constructor with that vector as a parameter. When I display the list in the interface it appears empty, which it’s senseless to me, I check that the vector has the correct data by printing it on the console, and so it does.

Here is the specific code snipet, and later the complete class.

Specific snipet:

query = "SELECT * FROM SENSORES WHERE IDDRONE = " + idDrone;
    rs = sentencia.executeQuery(query);
    String temp;
    Vector<String> vector = new Vector<String>();
    while(rs.next())
    {
        temp = rs.getString("ID") + " " + rs.getString("DESCRIPCION");
        vector.add(temp);
    }

    jList1 = new JList<String>(vector);
    System.out.println(vector);

And here is the entire class, the Jlist declaration is at the end:

package UI;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

import javax.swing.JList;

import sqlConnection.DatabaseConnection;


public class DeustoDronesJFrame extends javax.swing.JFrame {

/**
 * Creates new form DeustoDronesJFrame
 * @throws SQLException 
 */
public DeustoDronesJFrame() throws SQLException {
    initComponents();
}

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.
 * @throws SQLException 
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() throws SQLException {

    jLabel2 = new javax.swing.JLabel();
    jScrollPane1 = new javax.swing.JScrollPane();

    jLabel1 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jButton3 = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    jLabel2.setFont(new java.awt.Font("Times New Roman", 2, 18)); // NOI18N
    jLabel2.setForeground(new java.awt.Color(0, 0, 153));



    jScrollPane1.setViewportView(jList1);
    Statement sentencia = DatabaseConnection.getInstance().createStatement();
    String query = "SELECT * FROM DRONES";
    ResultSet rs = sentencia.executeQuery(query);
    String idDrone = rs.getString("IDDRONE");
    String estadoGPS = rs.getString("ESTADOGPS");
    System.out.println(estadoGPS);
    if (estadoGPS.equals(estadoGPS))
        estadoGPS = "OFF";
    else 
        estadoGPS = "ON";


    query = "SELECT * FROM SENSORES WHERE IDDRONE = " + idDrone;
    rs = sentencia.executeQuery(query);
    String temp;
    Vector<String> vector = new Vector<String>();
    while(rs.next())
    {
        temp = rs.getString("ID") + " " + rs.getString("DESCRIPCION");
        vector.add(temp);
    }

    jList1 = new JList<String>(vector);
    System.out.println(vector);

    jLabel1.setText("jLabel1");
    jLabel2.setText("Drone" + idDrone);
    jLabel3.setText("GPS " + estadoGPS);

    jButton1.setText("CAMBIAR ESTADO GPS");

    jButton2.setText("CAMBIAR ESTADO SENSOR");

    jButton3.setText("HISTORICO SENSOR");

    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(layout.createSequentialGroup()
            .add(24, 24, 24)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jLabel2)
                .add(layout.createSequentialGroup()
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 328, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(42, 42, 42)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                        .add(jButton2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(jButton3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .add(layout.createSequentialGroup()
                    .add(12, 12, 12)
                    .add(jLabel1)
                    .add(84, 84, 84)
                    .add(jLabel3)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                    .add(jButton1)))
            .addContainerGap(88, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(layout.createSequentialGroup()
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .add(26, 26, 26)
                    .add(jLabel2)
                    .add(24, 24, 24)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(jLabel1)
                        .add(jLabel3)))
                .add(layout.createSequentialGroup()
                    .add(63, 63, 63)
                    .add(jButton1)))
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 62, Short.MAX_VALUE)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 224, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(69, 69, 69))
                .add(layout.createSequentialGroup()
                    .add(59, 59, 59)
                    .add(jButton2)
                    .add(52, 52, 52)
                    .add(jButton3)
                    .addContainerGap())))
    );

    pack();
}// </editor-fold>//GEN-END:initComponents

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    /*
     * Set the Nimbus look and feel
     */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /*
     * If Nimbus (introduced in Java SE 6) is not available, stay with the
     * default look and feel. For details see
     * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(DeustoDronesJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(DeustoDronesJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(DeustoDronesJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(DeustoDronesJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /*
     * Create and display the form
     */
    java.awt.EventQueue.invokeLater(new Runnable() {

        public void run() {
            try {
                new DeustoDronesJFrame().setVisible(true);
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JList jList1;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration//GEN-END:variables
}

Thanks everyone.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T18:52:44+00:00Added an answer on June 4, 2026 at 6:52 pm

    You need to set the viewportview AFTER creating the JList.

    Like this:

    jList1 = new JList<String>(vector);   //First create list
    
    jScrollPane1.setViewportView(jList1); //Set viewport
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to fill some data from an xml feed we made into my
I am trying to fill gridpanel to get data from database through LINQ in
I am trying to fill up an NSmutableAray with data from sqlite database. ItemShow
I'm trying to fill a grid view using data from a db cursor using
I am trying to fill my view model with some drop down options from
I am trying to fill a livecycle created form with form data from django.
I am trying to fill remote data into picker, but it crashes. here is
I am trying to fill out a DataGridView with data from a database. The
I'm trying to fill a collection from an IDataReader that was returned by another
I'm trying to fill a asp.DataGrid with data from a DB2 database. The problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.