Hello! I'm having trouble building a table. It is as follows, the user defines a series of variables that are stored in a vector. I would like the variables stored in this array to be the name of the columns in the table. The problem does not involve sql, but rather variables passed through a java interface built by neatbeans. Thank you in advance.
A string vector (called a column) is used with the vector Concatenate function, which receives two arraysLists and stores it in a third. Then passing to the arrayList result. the values of the arraylist result is passed to the string str vector, returning its value to the column variable.
The following is the code below:
Statement arrays:
public ArrayList<String> colInput = new ArrayList<String>();
public ArrayList<String> colOutput = new ArrayList<String>();
Storage in arrays:
private void jButton1AddInputActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int i = jList4.getSelectedIndex();
if (i == -1) {
JFrame frame = new JFrame("Warning");
JOptionPane.showMessageDialog(frame, palavras.getString("Please, select a variable"));
} else {
tipoBotao = INICIAL;
String aux = Table.getVars().get(i).toString();
colInput.add(aux);
//System.out.println(colInput.get(j)); j++;
pressionarVariavelInput(aux);
escreverInput();
//escreverFormula();
}
}
private void jButton2AddOutputActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int i = jList4.getSelectedIndex();
if (i == -1) {
JFrame frame = new JFrame("Warning");
JOptionPane.showMessageDialog(frame, palavras.getString("Please, select a variable"));
} else {
tipoBotao = INICIAL;
String aux = Table.getVars().get(i).toString();
colOutput.add(aux);
//System.out.println(colOutput.get(k));k++;
pressionarVariavelOutput(aux);
escreverOutput();
//escreverFormula();
}
}
Calling the table:
String[] coluna = this.ConcatenaVetor(colInput, colOutput);
Object dados[][]= new Object[][]{};
jTable2 = new javax.swing.JTable(dados, coluna);
jScrollPane7.setViewportView(jTable2);
Concatenate vector function:
String[] ConcatenaVetor(ArrayList colInput, ArrayList colOutput){
int tam = colInput.size() + colOutput.size();
ArrayList<String> resultado = new ArrayList<String>();
resultado.addAll(colInput);
resultado.addAll(colOutput);
String[] str= new String[10];
for(int i = 0; i < colInput.size(); i++){
str[i] = resultado.get(i);
}
return str;
}