我正在尝试制作一个程序,使用 AbstractTableModel 显示临时文件夹中的所有文件,但我如何编写 getValueAt() 方法。文件名应该在第一列,文件路径应该在第二列。我暂时取消了它,但有人可以告诉我锄头我应该编码吗?
这是我到目前为止得到的:
public class UI extends JFrame {
private JPanel contentPane;
private JTable table;
File[] dir = new File(System.getProperty("java.io.tmpdir")).listFiles();
public static void main(String[] args) {
public UI() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 542, 422);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.TOP);
tabbedPane.setBounds(0, 0, 526, 384);
contentPane.add(tabbedPane);
JPanel panel = new JPanel();
tabbedPane.addTab("Temp Files", null, panel, null);
panel.setLayout(null);
final AbstractTableModel myAbstractTableModel = new AbstractTableModel() {
@Override
public int getColumnCount() {
return 2;
}
@Override
public int getRowCount() {
return dir.length;
}
@Override
public Object getValueAt(int arg0, int arg1) {
return null;
}
};
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(10, 11, 402, 334);
panel.add(scrollPane);
table = new JTable();
scrollPane.setViewportView(table);
table.setModel(myAbstractTableModel);
}
}