File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Column name not displayed!

 
Fox Shen
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For display the Flight Info with JTable, I implemented the FlightModel as following:

Now the JTable can display all the data info correctly, except for the column not found. According to the debug info, the columnNames are retrieved exactly, but just not displayed. Anyone know the reason, any comment would be appreciated!
-Fox
 
Michael Morris
Ranch Hand
Posts: 3451
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fox (know any good vixens?):
I'm analyzing your code and so far have not figured out why the column head is not displyed but will keep looking.
If you don't already have it, you need to download
Code Conventions for the JavaTM Programming Language
A lot of this code does not comply with those conventions and you will lose points on general considerations for that. Also you need to use one of the newer Collections in place of Vector.
Michael Morris
[ August 29, 2002: Message edited by: Michael Morris ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Fox"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it
here.
Thanks! and welcome to the JavaRanch!
Mark
 
Michael Morris
Ranch Hand
Posts: 3451
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fox,
I ran a test using your table model and the table headers displayed fine in the frame I created. Here's the simple frame I used:

There must be some other problem that you are missing.
Michael Morris
 
George Lawniczak
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To display headers, you must decorate your JTable with a JScrollPanel, or else the headers will not display.
 
Fox Shen
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael
Thanks for your comments and code example. I think I now know the reason for that. Just as shown in your code and mentioned by George, the JTable must be decorated with a JScrollPane, or the header will not display. In my own code, I just put it into a JPanel, I think that's the problem.
Fox Shen
 
ZhengQi Huang
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,Michael:
I wrote code like Fox Shen too,why did you say
A lot of this code does not comply with those conventions and you will lose points on general considerations for that.

Could you please tell me how to modify this code to comply with java code conventions???
And another question:why can't use Vector here?Which Collections should I take???
[ August 30, 2002: Message edited by: ZhengQi Huang ]
[ August 30, 2002: Message edited by: ZhengQi Huang ]
 
Michael Morris
Ranch Hand
Posts: 3451
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ZhengQi,
There are many code conventions that you should be aware of for this assignment. To view those conventions, click on the link of my first post.
To download the HTML version click the following link:
Java Code Conventions (Download HTML)
Here are some examples:
Don't do this:

Do this instead:


Don't do this:

Do this instead:

Never have lines over 80 characters. If you have to break up a long line of code, there are guidelines to where to break the line and many other items to make code very easy to read.

And another question:why can't use Vector here?Which Collections should I take???

Vector is one of the old Collections objects and the newer ones are now preferred. A good choice for a table model would be an ArrayList which has both the functionality of a dynamic array like Vector and implements the List interface. You could also use a HashMap by mapping a row to a record.
Hope this helps,
Michael Morris
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic