我的程序能夠讀取我的.txt文件,但由於某種原因,它無法將該數據放在我的表上。 (如果你需要我的代碼的任何其他部分,請告訴我)。我不確定究竟是什麼問題,但我已經嘗試幾乎所有的方法將其輸入到表格中,似乎沒有任何工作。我能夠手動輸入數據到表格中(使用創建按鈕),但由於某種原因,我無法導入數據。我無法讓我的程序從txt導入數據到Jtable
//initializing all of the buttons (and jtable, scroll pane)
this.jScrollPane1 = new JScrollPane();
this.pokeTable = new JTable();
this.programTitle = new JLabel();
this.searchText = new JTextField();
this.searchButton = new JButton();
this.createButton = new JButton();
this.deleteButton = new JButton();
this.displayInstructionsButton = new JButton();
this.exportPokedex = new JButton();
//sets close operation
setDefaultCloseOperation(3);
//makes my Jtable
this.pokeTable.setModel(new DefaultTableModel(
new Object[0][],
new String[] {"Name", "Region", "PokeNumber", "Type", "Habitat" }) //creating column headings
{
boolean[] canEdit = new boolean[5];
public boolean isCellEditable(int rowIndex, int columnIndex) //makes all of the cells editable
{
return this.canEdit[columnIndex];
}
});
IO.openInputFile("data/pokemon.txt");
int j =0;
while(IO.readLine()!=null){
j++;
}
IO.closeInputFile();
IO.openInputFile("data/pokemon.txt");
String[] pokemon2 = new String[5];
for(int i = j; i!=0; i--)
{
String s = IO.readLine();
pokemon2 = s.split(",");
DefaultTableModel model = (DefaultTableModel)this.pokeTable.getModel();
model.addRow(new Object[] { pokemon2[0], pokemon2[1], Integer.valueOf(pokemon2[2]), pokemon2[3], pokemon2[4] });
new Pokemon (pokemon2[0], pokemon2[1], Integer.valueOf(pokemon2[2]), pokemon2[3], pokemon2[4]);
for(int f = 0; f < pokemon2.length; f++){
System.out.println(pokemon2[f]);
System.out.println("");
}
}
IO.closeInputFile();
this.jScrollPane1.setViewportView(this.pokeTable); //makes table able to scroll
this.jScrollPane1.getViewport().setBackground(new Color (233, 116, 81)); //sets background of table (not cell colour)
//end of intializing JTable
//sets title of the program
this.programTitle.setText("Pokedex");
使用SO作爲調試器是一個糟糕的主意。就調試小程序而言,您嘗試過什麼?你是否試圖調試或打印值來測試你的斷言? – jdv