JTable does not show column names

1

I made a JDialog that will show some statistics of the users who use the software, but I am not able to make the name of the columns appear. I tried adding it using .addColumn in the template but it is not working.

class Estatisticas extends JDialog{
    public Estatisticas(){
        setIconImage(Toolkit.getDefaultToolkit().getImage(Sobre.class.getResource("/img/info.png")));
        setModal(true);
        setTitle("Estatísticas");
        setResizable(false);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setBounds(100, 100, 340, 300);
        JPanel contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);

        File[] diretorio = new File("./usuarios/").listFiles();
        DefaultTableModel modelo = new DefaultTableModel();
        modelo.addColumn("Usuário");
        modelo.addColumn("Acessos");
        String[] row = new String[2];

        for (File file : diretorio) {
            if (file.isFile()) {
                try {
                    row[0] = file.getName().substring(0, file.getName().length() - 11);
                    row[1] = retornaAcessoArquivo(file.getName());
                    modelo.addRow(row);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }

        JTable tblEstatisticas = new JTable(modelo);
        contentPane.add(tblEstatisticas);
    }
}
    
asked by anonymous 27.03.2015 / 19:11

1 answer

1

You should put your table in a JScrollPane.

JScrollPane scroll = new JScrollPane(tblEstatisticas);
contentPane.add(scroll);
    
09.04.2015 / 06:12