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
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
To display headers, you must decorate your JTable with a JScrollPanel, or else the headers will not display.
Joined: Apr 20, 2002
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
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.
Joined: Jan 30, 2002
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