Domanda

I have a weird problem with my combo box... (I use Netbeans 7.1 and Java code) when I add an item cbxUnidad.addItem("TODOS"); it takes 1300 ms to add it, so when I open that form (on execution time) it takes more than 4 seconds to open it. I know that that specific code takes that long because i have used this to know how much time takes that line:

long empieza  = 0;
long duracion = 0;
empieza  = System.currentTimeMillis();
cbxUnidad.addItem("TODOS");
duracion = (System.currentTimeMillis() - empieza);
System.out.pr

intln("Adding the item TODOS last " + duracion + " ms");

So in that way i get 1.3 seconds (1300 ms) when java execute that sentence... that's kinda weird and very slow... so i wanna know if anyone knows why or how to change the sentence.

Here i Leave the initCode for the combo-box:

cbxUnidad = new javax.swing.JComboBox();
cbxUnidad.setMaximumRowCount(25);
cbxUnidad.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
cbxUnidad.addItemListener(new java.awt.event.ItemListener() {
    public void itemStateChanged(java.awt.event.ItemEvent evt) {
        cbxUnidadItemStateChanged(evt);
        }
});

Thank you a lot :)

È stato utile?

Soluzione

You'r probably doing some other operations unless adding only one item to a combo doesn't take too much time (actually it doesn't make sense adding one item taking 1.3 seconds).
My advice is :

  • Create another class having one combobox .
  • Add item(s) to the combobox and see how much time it takes.

    long empieza  = 0;
    long duracion = 0;
    empieza  = System.currentTimeMillis();
    cbxUnidad.addItem("TODOS");
    duracion = (System.currentTimeMillis() - empieza);
    java.text.NumberFormat nf = new java.text.DecimalFormat("#0.00000");
    String totalTime = nf.format(totalTime/1000d);
    System.out.println("Adding the item TODOS last " + totalTime+ " seconds");
    
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top