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
Joined: Jan 30, 2002
Posts: 3451
posted
0
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 ]
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
"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
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
Joined: Aug 12, 2002
Posts: 27
posted
0
To display headers, you must decorate your JTable with a JScrollPanel, or else the headers will not display.
Fox Shen
Greenhorn
Joined: Apr 20, 2002
Posts: 16
posted
0
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
Joined: Aug 13, 2002
Posts: 9
posted
0
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 ]
I am a beginner.
Michael Morris
Ranch Hand
Joined: Jan 30, 2002
Posts: 3451
posted
0
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