JTable header not showing












4















JTable header not showing...



My JTable header wont show even if add it into a container like JScrollPane...tell me why is it happen and how can i fix it or debug it.. I search through internet and all they saying is add container to your jtable, i did but still my header are not showing.





public void table(){

try{

rs = stat.executeQuery("SELECT * FROM payments;");

Vector<String> header = new Vector<String>();

header.add("PAYMENT");
header.add("AMOUNT");
header.add("MODIFIER");
header.add("DATE MODIFIED");

Vector<Vector<Object>> data = new Vector<Vector<Object>>();

while(rs.next()) {

Vector<Object> row = new Vector<Object>();

row.add(rs.getString("description"));
row.add(rs.getString("amount"));
row.add(rs.getString("remarks"));
row.add(rs.getString("date"));


data.add(row);

} // loop

table = new JTable(data, header);

JScrollPane scrollPane = new JScrollPane(table);

panel.add(table);
panel.add(table.getTableHeader());
//panel.removeAll();
//scroll.add(table);
validate();

}catch(Exception e){
System.out.println("Error in table: "+e);
}//try and catch

}









share|improve this question





























    4















    JTable header not showing...



    My JTable header wont show even if add it into a container like JScrollPane...tell me why is it happen and how can i fix it or debug it.. I search through internet and all they saying is add container to your jtable, i did but still my header are not showing.





    public void table(){

    try{

    rs = stat.executeQuery("SELECT * FROM payments;");

    Vector<String> header = new Vector<String>();

    header.add("PAYMENT");
    header.add("AMOUNT");
    header.add("MODIFIER");
    header.add("DATE MODIFIED");

    Vector<Vector<Object>> data = new Vector<Vector<Object>>();

    while(rs.next()) {

    Vector<Object> row = new Vector<Object>();

    row.add(rs.getString("description"));
    row.add(rs.getString("amount"));
    row.add(rs.getString("remarks"));
    row.add(rs.getString("date"));


    data.add(row);

    } // loop

    table = new JTable(data, header);

    JScrollPane scrollPane = new JScrollPane(table);

    panel.add(table);
    panel.add(table.getTableHeader());
    //panel.removeAll();
    //scroll.add(table);
    validate();

    }catch(Exception e){
    System.out.println("Error in table: "+e);
    }//try and catch

    }









    share|improve this question



























      4












      4








      4


      1






      JTable header not showing...



      My JTable header wont show even if add it into a container like JScrollPane...tell me why is it happen and how can i fix it or debug it.. I search through internet and all they saying is add container to your jtable, i did but still my header are not showing.





      public void table(){

      try{

      rs = stat.executeQuery("SELECT * FROM payments;");

      Vector<String> header = new Vector<String>();

      header.add("PAYMENT");
      header.add("AMOUNT");
      header.add("MODIFIER");
      header.add("DATE MODIFIED");

      Vector<Vector<Object>> data = new Vector<Vector<Object>>();

      while(rs.next()) {

      Vector<Object> row = new Vector<Object>();

      row.add(rs.getString("description"));
      row.add(rs.getString("amount"));
      row.add(rs.getString("remarks"));
      row.add(rs.getString("date"));


      data.add(row);

      } // loop

      table = new JTable(data, header);

      JScrollPane scrollPane = new JScrollPane(table);

      panel.add(table);
      panel.add(table.getTableHeader());
      //panel.removeAll();
      //scroll.add(table);
      validate();

      }catch(Exception e){
      System.out.println("Error in table: "+e);
      }//try and catch

      }









      share|improve this question
















      JTable header not showing...



      My JTable header wont show even if add it into a container like JScrollPane...tell me why is it happen and how can i fix it or debug it.. I search through internet and all they saying is add container to your jtable, i did but still my header are not showing.





      public void table(){

      try{

      rs = stat.executeQuery("SELECT * FROM payments;");

      Vector<String> header = new Vector<String>();

      header.add("PAYMENT");
      header.add("AMOUNT");
      header.add("MODIFIER");
      header.add("DATE MODIFIED");

      Vector<Vector<Object>> data = new Vector<Vector<Object>>();

      while(rs.next()) {

      Vector<Object> row = new Vector<Object>();

      row.add(rs.getString("description"));
      row.add(rs.getString("amount"));
      row.add(rs.getString("remarks"));
      row.add(rs.getString("date"));


      data.add(row);

      } // loop

      table = new JTable(data, header);

      JScrollPane scrollPane = new JScrollPane(table);

      panel.add(table);
      panel.add(table.getTableHeader());
      //panel.removeAll();
      //scroll.add(table);
      validate();

      }catch(Exception e){
      System.out.println("Error in table: "+e);
      }//try and catch

      }






      java database swing methods jtable






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 28 '13 at 10:43









      MadProgrammer

      299k17153266




      299k17153266










      asked Sep 28 '13 at 10:34









      PhantomKidPhantomKid

      57311




      57311
























          2 Answers
          2






          active

          oldest

          votes


















          10














          Start by removing



          panel.add(table.getTableHeader());


          The JTable is designed to add it's header to the JScrollPane. An instance of a component can only belong to a one parent/container, the above line is removing it from the scrollpane



          Also, change this...



          panel.add(table);


          To



          panel.add(scrollPane);





          share|improve this answer
























          • when i do that (panel.add(scrollPane)) it shows me nothing..

            – PhantomKid
            Sep 28 '13 at 13:49











          • thit worked hahaha...thanks! btw this is my another error why i keeping get blank table i set the bounds of my table instead of the scrollpane... =]

            – PhantomKid
            Sep 28 '13 at 13:54






          • 1





            Use an appropriate LayoutManager instead

            – MadProgrammer
            Sep 28 '13 at 19:59



















          3














          Same problem I have face
          You have to add the JTable to the JScrollPane then add JscrollPane to JFrame
          e.g.



          JTable table = new JTable();
          JScrollPane scrollPane= new JScrollPane(table);
          frame.add(scrollPane);





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19065970%2fjtable-header-not-showing%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            10














            Start by removing



            panel.add(table.getTableHeader());


            The JTable is designed to add it's header to the JScrollPane. An instance of a component can only belong to a one parent/container, the above line is removing it from the scrollpane



            Also, change this...



            panel.add(table);


            To



            panel.add(scrollPane);





            share|improve this answer
























            • when i do that (panel.add(scrollPane)) it shows me nothing..

              – PhantomKid
              Sep 28 '13 at 13:49











            • thit worked hahaha...thanks! btw this is my another error why i keeping get blank table i set the bounds of my table instead of the scrollpane... =]

              – PhantomKid
              Sep 28 '13 at 13:54






            • 1





              Use an appropriate LayoutManager instead

              – MadProgrammer
              Sep 28 '13 at 19:59
















            10














            Start by removing



            panel.add(table.getTableHeader());


            The JTable is designed to add it's header to the JScrollPane. An instance of a component can only belong to a one parent/container, the above line is removing it from the scrollpane



            Also, change this...



            panel.add(table);


            To



            panel.add(scrollPane);





            share|improve this answer
























            • when i do that (panel.add(scrollPane)) it shows me nothing..

              – PhantomKid
              Sep 28 '13 at 13:49











            • thit worked hahaha...thanks! btw this is my another error why i keeping get blank table i set the bounds of my table instead of the scrollpane... =]

              – PhantomKid
              Sep 28 '13 at 13:54






            • 1





              Use an appropriate LayoutManager instead

              – MadProgrammer
              Sep 28 '13 at 19:59














            10












            10








            10







            Start by removing



            panel.add(table.getTableHeader());


            The JTable is designed to add it's header to the JScrollPane. An instance of a component can only belong to a one parent/container, the above line is removing it from the scrollpane



            Also, change this...



            panel.add(table);


            To



            panel.add(scrollPane);





            share|improve this answer













            Start by removing



            panel.add(table.getTableHeader());


            The JTable is designed to add it's header to the JScrollPane. An instance of a component can only belong to a one parent/container, the above line is removing it from the scrollpane



            Also, change this...



            panel.add(table);


            To



            panel.add(scrollPane);






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Sep 28 '13 at 10:39









            MadProgrammerMadProgrammer

            299k17153266




            299k17153266













            • when i do that (panel.add(scrollPane)) it shows me nothing..

              – PhantomKid
              Sep 28 '13 at 13:49











            • thit worked hahaha...thanks! btw this is my another error why i keeping get blank table i set the bounds of my table instead of the scrollpane... =]

              – PhantomKid
              Sep 28 '13 at 13:54






            • 1





              Use an appropriate LayoutManager instead

              – MadProgrammer
              Sep 28 '13 at 19:59



















            • when i do that (panel.add(scrollPane)) it shows me nothing..

              – PhantomKid
              Sep 28 '13 at 13:49











            • thit worked hahaha...thanks! btw this is my another error why i keeping get blank table i set the bounds of my table instead of the scrollpane... =]

              – PhantomKid
              Sep 28 '13 at 13:54






            • 1





              Use an appropriate LayoutManager instead

              – MadProgrammer
              Sep 28 '13 at 19:59

















            when i do that (panel.add(scrollPane)) it shows me nothing..

            – PhantomKid
            Sep 28 '13 at 13:49





            when i do that (panel.add(scrollPane)) it shows me nothing..

            – PhantomKid
            Sep 28 '13 at 13:49













            thit worked hahaha...thanks! btw this is my another error why i keeping get blank table i set the bounds of my table instead of the scrollpane... =]

            – PhantomKid
            Sep 28 '13 at 13:54





            thit worked hahaha...thanks! btw this is my another error why i keeping get blank table i set the bounds of my table instead of the scrollpane... =]

            – PhantomKid
            Sep 28 '13 at 13:54




            1




            1





            Use an appropriate LayoutManager instead

            – MadProgrammer
            Sep 28 '13 at 19:59





            Use an appropriate LayoutManager instead

            – MadProgrammer
            Sep 28 '13 at 19:59













            3














            Same problem I have face
            You have to add the JTable to the JScrollPane then add JscrollPane to JFrame
            e.g.



            JTable table = new JTable();
            JScrollPane scrollPane= new JScrollPane(table);
            frame.add(scrollPane);





            share|improve this answer




























              3














              Same problem I have face
              You have to add the JTable to the JScrollPane then add JscrollPane to JFrame
              e.g.



              JTable table = new JTable();
              JScrollPane scrollPane= new JScrollPane(table);
              frame.add(scrollPane);





              share|improve this answer


























                3












                3








                3







                Same problem I have face
                You have to add the JTable to the JScrollPane then add JscrollPane to JFrame
                e.g.



                JTable table = new JTable();
                JScrollPane scrollPane= new JScrollPane(table);
                frame.add(scrollPane);





                share|improve this answer













                Same problem I have face
                You have to add the JTable to the JScrollPane then add JscrollPane to JFrame
                e.g.



                JTable table = new JTable();
                JScrollPane scrollPane= new JScrollPane(table);
                frame.add(scrollPane);






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 12 '14 at 5:44









                KundanKundan

                121210




                121210






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19065970%2fjtable-header-not-showing%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to send String Array data to Server using php in android

                    Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                    Is anime1.com a legal site for watching anime?