Aaron
Aaron

Reputation: 47

JAVA jtable passing value

I am facing the problem of passing value to print it out in the jtable. I am trying to pass my data variable to the table but I am getting error once I trying to run the project. The image below shown what i tried.enter image description here

I declare these 2 variable in global.

Vector<Vector<Object>> data = new Vector<Vector<Object>>();

String[] headers = {"IP", "Port", "Destination", "Port"};

I pass in the value what i read from the text file into data variable as this:

Vector<Object> row = new Vector<Object>();
row.add(allTCP.get(x).getTCPSourceIP());
row.add(allTCP.get(x).getTCPSourcePort());
row.add(allTCP.get(x).getTCPDestIP());
row.add(allTCP.get(x).getTCPDestPort());
data.add(row);

Can anyone tell me what i did wrong or what shall i do in order for me pass in the value to output as table form. By the way, I designed my table in third tab.

Upvotes: 0

Views: 769

Answers (1)

camickr
camickr

Reputation: 324128

Read the DefaultTableModel API.

You can create a DefaultTableModel using:

  1. an Array of column names and a 2 dimensional array of data, or
  2. an Vector of column names and a Vector of Vectors for the data.

You can't create the model using an array and a Vector.

Upvotes: 3

Related Questions