Jump to content

Adding a value to a jTable (GUI help)


Recommended Posts

Posted (edited)

Hey there, so im making a fighting script and im trying to make a method for creating a list of items to pick up that the user can put in. the problem im running into right now is that i beleive im doing everything right but on the button press it doesnt add anything to the table. This is my current code. 

 

 
this is how the gui looks if a visual is needed.
 
post-146248-0-44221900-1463351087_thumb.png
Edited by roguehippo
Posted (edited)

 

Hey there, so im making a fighting script and im trying to make a method for creating a list of items to pick up that the user can put in. the problem im running into right now is that i beleive im doing everything right but on the button press it doesnt add anything to the table. This is my current code. 

 

 
this is how the gui looks if a visual is needed.
 

 

String[] columnNames = { "Username", "Rank" };

		JTable table = new JTable(new DefaultTableModel(data.getData(), columnNames){
			@Override
		    public boolean isCellEditable(int row, int column) {
				//Disable editing of all cells 
		       return false;
		    }
			
		});

public Object[][] getData() {
		Object[][] data = new Object[num of entries][num column];
		int i = 0;
		for(String s : inputMap.keySet()){
			data[i][0] = "entry i, column 0";
			data[i][1] = "entry i, column 1";
			i++;
			} else{
			continue;
			}
		}
		return data;
	}

some leaked code. I had a Data class that would write and read to a file and it puts the data into a Object[][] and then the table can load it. The first dimension in the array is the entry count, the second dimension is the column amount. For example if I had 2 entries and each entry had a name, birthdate, and hometown it would be Object[2][3] and then it would populate 3 columns with 2 entries.

Edited by LoudPacks
  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...