Results 1 to 3 of 3
  1. #1
    stylian is offline Member
    Join Date
    Oct 2009
    Posts
    4
    Rep Power
    0

    Default DefaultTableModel problem

    hello guys.. I m trying to create a graphic table useing the class DefaultTableModel.
    So, the problem is that it does not print the title of each column.
    For example, i want to print in the window the following :

    ID Title
    1 lol
    2 lala

    the following code prints only
    1 lol
    2 lala

    without the titles..

    Java Code:
    JFrame frame = new JFrame("Select Registration");
        JPanel panel = new JPanel();
        //String types[]= {"id", "title", "username","password","url","notes"};
        String data[][] = { {"132","facebook"}};
       // String col[] = {"Name","code"};
    
    
        String types[] = {"id","title"};
        /*
        Vector types =new Vector() ;
        types.add("id");
        types.add("title");
        types.add("username");
        types.add("password");
        types.add("url");
        types.add("notes");
        */
        DefaultTableModel model = new DefaultTableModel(data,types);
        
        JTable table = new JTable(model);
    
        panel.add(table);
        frame.add(panel);
        
        //frame.setSize(300, 300);
        frame.setVisible(true);
        frame.setResizable(true);
    Please! need help!

    thnx :)
    Last edited by stylian; 10-31-2009 at 04:21 PM.

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    12

    Default

    Edit your posting and use the "Code" tags on your code so the code retains its formatting properly. Its good practice for your next question.

    Java Code:
    panel.add(table);
    frame.add(panel);
    should be:

    Java Code:
    JScrollPane scrollPane = new JScrollPane(table);
    frame.add(scrollPane);

  3. #3
    stylian is offline Member
    Join Date
    Oct 2009
    Posts
    4
    Rep Power
    0

Similar Threads

  1. RequestFocus on DefaultTableModel Particular Cell
    By yernikumar in forum AWT / Swing
    Replies: 1
    Last Post: 03-01-2009, 04:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •