Results 1 to 5 of 5

Thread: How to use Tables in Java?

  1. #1
    Join Date
    Aug 2006
    Posts
    287

    How to use Tables in Java?

    Hello friends,
    Last time you guys solved my query for that I am very thankful. I need your help now also. I have just started the Java after completing the HTML and C++ programming language. I Java, I have done some basic programs by using some methods and functions. I want to use the table, so that I can display the list of the students to the user. But I don't know how to use..?! So please tell me how to use Tables in Java.?? Hoping that this time also you will help me soon..!!
    Dimension 1100 (FMY032J) mini-tower
    2.53ghz Intel Pentium 4
    80 gig nfts HDD
    512 RAM
    Main circuit board: Dell 0CF458
    BIOS: Dell A00
    Display: Intel(R) 82865G Graphics Controller [Display adaptor]
    Multimedia: Sound MAX Integrated Digital Audio
    Windows XP Home SP2

  2. #2
    Join Date
    Mar 2008
    Posts
    349

    Re: How to use Tables in Java?

    In Java, you can display tables of data by using the JTable class. JTable simply view your data and your data is not cached by that class. You can use the following code for creating the data.
    Code:
        String[] columnNames = {"Name",
                                "Place",
                                "Game",
                                "Age",
                                "Color"};
    
    Its data is initialized and stored in a two-dimensional Object array:
    
        Object[][] data = {
            {"Nuyrew", "California",
             "Snowboarding", new Integer(7), new Boolean(false)},
            {"Fyun", "Humi",
             "Rowing", new Integer(5), new Boolean(true)},
            {"Kathy", "Indies",
             "Knitting", new Integer(4), new Boolean(false)},
            {"Sharon", "Zakhour",
             "Speed reading", new Integer(20), new Boolean(true)},
            {"Philip", "Milan",
             "Pool", new Integer(10), new Boolean(false)}
        };

  3. #3
    Join Date
    Mar 2008
    Posts
    672

    Re: How to use Tables in Java?

    The JTable constructors has two types, they are :
    1. JTable(Object[][] rowData, Object[] columnNames)
    2. JTable(Vector rowData, Vector columnNames)

    The above mentioned constructors are very easy to use. Some disadvantages of them are :
    1. After using that constructor every cell automatically becomes editable.
    2. They treat all data types the same and that too all as strings.

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How to use Tables in Java?

    If the table that you are using is without the scroll pane, then you must get the table header component and place it yourself. The following code will help you for this :
    Code:
    container.setLayout(new BorderLayout());
    container.add(table.getTableHeader(), BorderLayout.PAGE_START);
    container.add(table, BorderLayout.CENTER);

  5. #5
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to use Tables in Java?

    You can use the following code for the table :
    Code:
    TableColumn column = null;
    for (int i = 0; i < 5; i++) {
        column = table.getColumnModel().getColumn(i);
        if (i == 2) {
            column.setPreferredWidth(100);
        } else {
            column.setPreferredWidth(50);
        }
    }

Similar Threads

  1. How to Print Tables using Swings in Java?
    By NIcaBoy in forum Software Development
    Replies: 5
    Last Post: 16-02-2010, 02:49 AM
  2. Reading tables in java.io
    By Miles Runner in forum Software Development
    Replies: 5
    Last Post: 20-01-2010, 10:30 AM
  3. Creating Tables in Java
    By RockOn in forum Software Development
    Replies: 3
    Last Post: 09-04-2009, 10:57 PM
  4. SQL - Update via 2 Tables
    By Bantu in forum Software Development
    Replies: 3
    Last Post: 19-01-2009, 08:39 PM
  5. Combining two tables
    By !const in forum Software Development
    Replies: 5
    Last Post: 26-11-2008, 07:21 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,576,519.86783 seconds with 17 queries