我有一個物件矩陣,我必須用字串填充它。我怎樣才能做到這一點?讓我好好解釋一下,我已經宣告了一個固定大小的物件矩陣,現在我必須通過 for 回圈填充它,我怎樣才能訪問矩陣的單元格。我把矩陣的代碼寫下來。抱歉,是意大利語。Giorno = 天,礦石 = 小時
tabMedie = new JTable();
tabMedie.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
tabMedie.setFont(new Font("Times New Roman", Font.PLAIN, 10));
tabMedie.setModel(new DefaultTableModel(
new Object[][] {
{"Orari", "Giorno 1", "Giorno 2", "Giorno 3", "Giorno 4", "Giorno 5", "Giorno 6", "Giorno 7"},
{"1", "", "", "", "", "", "", ""},
{"2", "", "", "", "", "", "", ""},
{"3", "", "", "", "", "", "", ""},
{"4", "", "", "", "", "", "", ""},
{"5", "", "", "", "", "", "", ""},
{"6", "", "", "", "", "", "", ""},
{"7", "", "", "", "", "", "", ""},
{"8", "", "", "", "", "", "", ""},
{"9", "", "", "", "", "", "", ""},
{"10", "", "", "", "", "", "", ""},
{"11", "", "", "", "", "", "", ""},
{"12", "", "", "", "", "", "", ""},
{"13", "", "", "", "", "", "", ""},
{"14", "", "", "", "", "", "", ""},
{"15", "", "", "", "", "", "", ""},
{"16", "", "", "", "", "", "", ""},
{"17", "", "", "", "", "", "", ""},
{"18", "", "", "", "", "", "", ""},
{"19", "", "", "", "", "", "", ""},
{"20", "", "", "", "", "", "", ""},
{"21", "", "", "", "", "", "", ""},
{"22", "", "", "", "", "", "", ""},
{"23", "", "", "", "", "", "", ""},
{"24", "", "", "", "", "", "", ""},
},
new String[] {
"Ore", "Giorno 1", "Giorno 2", "Giorno 3", "Giorno 4", "Giorno 5", "Giorno 6", "Giorno 7"
}
) {
Class[] columnTypes = new Class[] {
String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class
};
public Class getColumnClass(int columnIndex) {
return columnTypes[columnIndex];
}
boolean[] columnEditables = new boolean[] {
true, false, false, false, true, true, true, true
};
public boolean isCellEditable(int row, int column) {
return columnEditables[column];
}
});
tabMedie.getColumnModel().getColumn(0).setResizable(false);
tabMedie.getColumnModel().getColumn(1).setResizable(false);
tabMedie.getColumnModel().getColumn(2).setResizable(false);
tabMedie.getColumnModel().getColumn(3).setResizable(false);
tabMedie.getColumnModel().getColumn(4).setResizable(false);
tabMedie.getColumnModel().getColumn(5).setResizable(false);
tabMedie.getColumnModel().getColumn(6).setResizable(false);
tabMedie.getColumnModel().getColumn(7).setResizable(false);
tabMedie.setBounds(503, 36, 662, 401);
frmTemperature.getContentPane().add(tabMedie);
uj5u.com熱心網友回復:
首先,將“矩陣”(實際上是一個二維陣列)存盤在一個變數中:
String[][] texts = { { "Ora", "Giorno 1", … }, … };
然后,您可以在 for 回圈中使用它:
for (int x = 1; x < 8; x ) {
for (int y = 1; y < texts.length; y ) {
texts[y][x] = "Your Text Here";
}
}
最后,您可以將它作為引數傳遞給方法:
new DefaultTableModel(texts, new String[] { … }) { … };
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/447984.html
上一篇:在JSON物件串列中查找唯一值
