0

I have loaded the rows of the data from the database in the list.Now,i am trying to display the list of datas on the JPanel which is loaded inside the parent JPanel on button click. I have retreived the list of data but not able to display the data on the JPanel.
Any guides will be appreciated.

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by musthafa.aj
0
public class example
{
    private JPanel mainPanel = new JPanel();
 
    public example()
    {
        String[] header = 
        {
            "Header 1", "Header 2" ///////add colun name
        };
        String[][] data = new String[20][2];//put data received from database...
        for (int i = 0; i < data.length; i++)
        {
            for (int j = 0; j < data[i].length; j++)
            {
                data[i][j] = "Data [" + i + "][" + j + "]"; 
            }
        }
        JTable table = new JTable(data, header);
        
        JPanel sidePanel = new JPanel();
        JLabel sideLabel = new JLabel("Side Label");
        sidePanel.add(sideLabel);
        
        JPanel viewPanel = new JPanel();
        viewPanel.setLayout(new BorderLayout());
        viewPanel.add(table, BorderLayout.CENTER);
        viewPanel.add(sidePanel, BorderLayout.EAST);
        
        
        JScrollPane scroll = new JScrollPane(viewPanel);
        scroll.setColumnHeaderView(table.getTableHeader());
        
        mainPanel.setLayout(new BorderLayout());
        mainPanel.add(scroll, BorderLayout.CENTER);
        
    }
 
    public JPanel getMainPanel()
    {
        return mainPanel;
    }
 
    private static void createAndShowUI()
    {
        JFrame frame = new JFrame("TableAndStuff");
        frame.getContentPane().add(new example().getMainPanel());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
 
    public static void main(String[] args)
    {
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                createAndShowUI();
            }
        });
    }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.