Results 1 to 3 of 3
  1. #1
    uthpalaw is offline Member
    Join Date
    Mar 2010
    Posts
    68
    Rep Power
    0

    Default How to create a jtable

    I just created a jtable using windowbuilder, but it only displays column values, not column names. Any one has idea why is this ?

    <code>
    package pers.uthpala.msc.gui.admin;

    import java.awt.BorderLayout;

    public class Table extends JFrame {

    private JPanel contentPane;
    private JTable table;

    /**
    * Launch the application.
    */
    public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
    public void run() {
    try {
    Table frame = new Table();
    frame.setVisible(true);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    });
    }

    /**
    * Create the frame.
    */
    public Table() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    table = new JTable();
    table.setBorder(UIManager.getBorder("TableHeader.c ellBorder"));
    table.setColumnSelectionAllowed(true);
    table.setModel(new DefaultTableModel(
    new Object[][] {
    {"Uthpala", "29"},
    {"Tharindu", "29"},
    {null, null},
    },
    new String[] {
    "Name", "Age"
    }
    ));
    table.getColumnModel().getColumn(0).setPreferredWi dth(110);
    table.getColumnModel().getColumn(1).setPreferredWi dth(100);
    table.setBounds(10, 21, 240, 76);
    contentPane.add(table);
    }

    }

    </code>

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: How to create a jtable

    Quote Originally Posted by uthpalaw View Post
    I just created a jtable using windowbuilder
    What's windowbuilder? It doesn't appear to be a part of AWT/Swing.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: How to create a jtable

    I just created a jtable using windowbuilder, but it only displays column values, not column names. Any one has idea why is this ?
    The API should be your first source of reference: JTable (Java Platform SE 6)

    Note that if you wish to use a JTable in a standalone view (outside of a JScrollPane) and want the header displayed, you can get it using getTableHeader() and display it separately.
    And a word of advice: don't use a null layout.

Similar Threads

  1. Replies: 1
    Last Post: 10-02-2011, 09:41 PM
  2. jTable
    By mharsijamel in forum New To Java
    Replies: 2
    Last Post: 09-11-2011, 09:00 PM
  3. JTable - Please Help
    By BeeGee in forum Advanced Java
    Replies: 4
    Last Post: 05-27-2010, 05:16 PM
  4. Adding New JTable in JTable
    By anilkumar_vist in forum New To Java
    Replies: 0
    Last Post: 01-27-2010, 08:27 AM
  5. Replies: 2
    Last Post: 05-15-2008, 10:15 AM

Posting Permissions

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