I have a character, integer hashmap in which I want the characters displayed in one column of my JTable and my integers displayed in another. What would be the best way to achieve this and properly display it?
Asked
Active
Viewed 23 times
0
-
Easiest way is to use a `DefaultTableModel` and iterate through the map, adding rows with the key/value pairs (that is assuming you know how to iterate through a map. If not, you may want to search for _that_ first. Then search for how to add a row to a JTable/DefaultTableModel). [Hint](http://docs.oracle.com/javase/7/docs/api/javax/swing/table/DefaultTableModel.html#addRow%28java.lang.Object[]%29) – Paul Samsotha Oct 11 '14 at 03:03
-
Thank you, right now I have my map being iterated by a couple other loops so hopefully it won't be too much of a problem. Didn't realize JTables were so in depth... – execv3 Oct 11 '14 at 03:17
-
Work on it, and if you get stuck, edit your post with your attempt. We can help you fish out any mistakes. – Paul Samsotha Oct 11 '14 at 03:22
-
See also [*JTable: Editors and Renderers*](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#editrender). – trashgod Oct 11 '14 at 11:42