項目のリストを表示する GUI クラスを作成しました。ユーザーが項目を選択すると、JTable を表示する新しいウィンドウが表示され、その項目の詳細情報が表示されます (2 つの列: 左側にパラメーター、右側に値)。ユーザーが同時に複数のテーブル ウィンドウを開きたい場合に備えて、テーブル クラスのすべてのメソッドと変数を非静的にすることを決定するまで、これは (一種の) 機能していました。
そして、それは機能しなくなりました。テーブルは表示されません。モデルの add メソッドを使用した後でも、すべてのコードが実行されますが、テーブルは空です。
(また、主にフィールドの 1 つが「説明」と呼ばれ、非常に長くなる可能性があるため、GUI のより良いアイデアについてコメントをいただければ幸いです。私は自分でアプリケーションを書いているので、機能が最優先です)
編集: ここにいくつかのコードがあります。詳細についてはお気軽にお問い合わせください。(私はそれが十分に単純だと思ったので、そもそもコピーしませんでした)
82 行目から始まる JTable クラス - 残りはすべて自動的に生成されます。
public void main(ArrayList<String> l, ArrayList<String> d) {
labels = l;
data = d;
/*
* Set the Nimbus look and feel
*/
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(PopupTable.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(PopupTable.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(PopupTable.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(PopupTable.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new PopupTable().setVisible(true);
model.addColumn("Description");
model.addColumn("Value");
for (int i = 0; i < data.size(); i++) {
Object[] r = {labels.get(i), data.get(i)};
System.out.println(labels.get(i) + data.get(i));
model.addRow(r);
}
Object[] asd = {"Name", "Skelet"};
model.addRow(asd);
}
});
}
public static void asd() {
System.out.println("Bazinga!");
}
private ArrayList<String> labels;
private ArrayList<String> data;
private DefaultTableModel model = new DefaultTableModel();
;
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable table;
// End of variables declaration
}
もう 1 つのクラスは、フィールド データ用と各データの説明用の 2 つのリストを送信して、この「メイン」メソッドを呼び出します (最初は「2000」を送信し、2 番目は「エクスペリエンス」を送信します)。前述したように、変数とメソッドが静的であればすべてが機能します。そうでない場合は、表示されないテーブルを除いて、すべてが機能します。
Table クラスを作成するために使用する外部クラスのコードを次に示します。
new PopupTable().main(list1, list2);