CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2006
    Location
    Baltimore, Maryland, USA
    Posts
    104

    Java Not Properly Shown

    I'm writing a java application which uses a JTable, but the issue I'm having when I run it, the column names do not appear. I'm configured Eclipse to compile as a Java 1.5 code successfully, but never got a working table despite not having any errors.

    Code:
    String Newdata[][] = {{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""}};
    String col[] = {"col1", "col2", "col3", "col4", "col5"};
    DefaultTableModel model = new DefaultTableModel(Newdata,col);
    JTable tblEdits = new JTable(model);
    From these 4 lines, I expected to see a table with 5 columns and 5 rows (including header with cols names). I put my JTable on a JPanel as it would be displayed. Am I doing anything wrong with this snippet?
    -= the best is yet to come =-

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Java Not Properly Shown

    To automatically display the column headers, put the table into a JScrollPane. Alternatively, you can pull the headers out (getTableHeader) and display them separately. See How To Use Tables.

    The function of good software is to make the complex appear to be simple...
    Grady Booch
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured