Jump to content
roguehippo

Adding a value to a jTable (GUI help)

Recommended Posts

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
Link to comment
Share on other sites

 

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...