|
SCSA, OCA, SCJP 5.0, SCJD, CCDH, CCAH http://www.linkedin.com/in/carlosamorillo
Cheers, Roberto Perillo
SCJP, SCWCD, SCJD, SCBCD
I think I got your question, which is, how can you find out what is the number of the record that is selected in the JTable, right?
This means that, the first row in the table certainly corresponds to the first entry in the Map.
I find out what is the number of the record being displayed in that row (by iterating the Map with keySet().iterator())
1. created my own custom AbstractTableModel: it keeps a List of Room-objects (containing recNo + all properties)
SCSA, OCA, SCJP 5.0, SCJD, CCDH, CCAH http://www.linkedin.com/in/carlosamorillo
No, because recNo has no meaning to a CSR. He won't care if it is record 225 or 5. It would maybe more meaningful if the recNo was some kind of room number (then I would probably show it in the table).Do you display the Record Number in the JTable?
My Room-object contains all the fields from the database file (name, location, smoking, date available,...) and the appropriate record number. It does not contain a String[] at all. Each field is just represented in the Room-object as a String or Integer or Boolean. So I have 2 conversion methods to convert an object to array and an array to object. And like you already thought of yourself: the index in the List has nothing to do with the recNo of a room, so recNo 15 can easily have index 0 in the List (the index in the List is the row of that Room-object in the JTable).If I understand you correctly it seems to me you have in your model an ArrayList that each element is the recNo (Integer of the Map<Integer, Room>) plus the String[] contained in the Room, correct?
I didn't implement the setValueAt() method because my table is a read-only one, so no need to change values. And the getValueAt() method looks like this:So no adding or subtracting 1 from the column value at allI guess in the Model methods getValueAt() and setValueAt() you add or substract 1 from the column if you don't display the Record Number?
SCSA, OCA, SCJP 5.0, SCJD, CCDH, CCAH http://www.linkedin.com/in/carlosamorillo
I think your approach is better than just working with a plain String[], but I believe it is not the best (most elegant) solution possible...., that I wonder know if it is an elegant solution?
You will end up with less code (don't have getters nor setters in my room-object), your code will also be easy to understand and less error prone (because array indexes are only used in the 2 conversion methods).I can see now the way you used it it does come handy and helpful to make your code pretty simple.
SCSA, OCA, SCJP 5.0, SCJD, CCDH, CCAH http://www.linkedin.com/in/carlosamorillo
Great job!I am able to get all the Hotel Rooms information loaded in the JTable's Model and to display it in my GUI.
No, I didn't. Here is a hintDid you do anything special to get the smoking boolean member variable displayed as a JCheckbox?
SCSA, OCA, SCJP 5.0, SCJD, CCDH, CCAH http://www.linkedin.com/in/carlosamorillo
SCSA, OCA, SCJP 5.0, SCJD, CCDH, CCAH http://www.linkedin.com/in/carlosamorillo
Excellent job!Carlos Morillo wrote:I got it to work!
I was also able to use it for the size field which is an int and it nicely right justifies it.
SCSA, OCA, SCJP 5.0, SCJD, CCDH, CCAH http://www.linkedin.com/in/carlosamorillo
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|