Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to display elements of HashMap onto Jtable or anyother using Swing  RSS feed

 
Siddharth Polisiti
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I want to display a Hash Map to a GUI
my hashmap contains data as follows
BC111S04=[22, 17302, 50, 17485], BC111S03=[22, 17302, 50, 17485], BC111S02=[22, 17302, 50, 17485], BC111S01=[22, 17302, 50, 17485], BC111SV1=[22, 17302, 50, 17485], BC111SV2=[22, 17302, 50, 17485], BC111M01=[22, 17302, 50, 17485]

in above BCXXXXXX is the Url of DB and the ones in Square bracket are results of some query
I want to display them in format as in below picture:
my code for GUI is as follows
Filename: untitled.bmp
File size: 870 Kbytes
 
Siddharth Polisiti
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Attached file contains how I excpect my GUI to be...Thanks! in advance!!!
 
Stephan van Hulst
Saloon Keeper
Posts: 7804
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Siddharth, welcome to CodeRanch.

First of all, what's your question? Nobody is going to try and run your code just to find out what your question is.

I'm guessing you're having a hard time showing the contents of a map into a table. So write the simplest code you can to do just that, report what you expected to see and what problem you're experiencing. And please, when you post code, UseCodeTags.
 
Siddharth Polisiti
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Stephan ...Thanks for the reply.

I just wanted to ask I have my Hashmap as follows:


BC111S04=[22, 17302, 50, 17485], BC111S03=[22, 17302, 50, 17485], BC111S02=[22, 17302, 50, 17485], BC111S01=[22, 17302, 50, 17485], BC111SV1=[22, 17302, 50, 17485], BC111SV2=[22, 17302, 50, 17485], BC111M01=[22, 17302, 50, 17485]

Here BC111S04 and BC111M01... and so on are keys and [22,17302,50,17485] are the corresponding values.

I want to display it in GUI using Swing as following in row - column format

Keys ----> BC111S04 BC111S03 .....so on.............. BC111M01

Value1 22 22 .......................... 22

Value2 17302 17302 ........................ 17302

Value3 50 50 ........................... 50

Value4 17485 17485 ................ ........ 17485

 
Rob Camick
Ranch Hand
Posts: 2800
15
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Use Swing components. Button, TextField etc. are AWT components. Swing components start with a "J", JButton, JTextField etc.

2. A HashMap is not a good structure for storing data when using a JTable. A HashMap does not have the concept of "rows". So you would need to copy the data from the HashMap to the DefaultTableModel where you can specify rows of data that you want to add the model. Read the Swing tutorial on How to Use Tables for working examples to get you started. And check out the API for the DefaultTableModel for methods you can use to add data to the model.
 
Campbell Ritchie
Marshal
Posts: 55681
162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You should always use code tags; since you are new I have added them and removed lots of blank space, and doesn't it look better
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!