wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes How to display values in JTable??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "How to display values in JTable???" Watch "How to display values in JTable???" New topic

How to display values in JTable???

jyothi sunke
Ranch Hand

Joined: Sep 11, 2002
Posts: 65
Hi all,
I have record values in a String array. I got stuck there...Which constructor is best to invoke JTable??
JTable(TableModel dm)
JTable(TableModel dm, TableColumnModel cm)
JTable(Vector rowData, Vector columnNames)
JTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm)
I wrote MyTableModel which extends AbstractTableModel. I didn't write the TableColumnModel yet..That I do soon...But in Table model, How to give row data??
for columsheaders---I used String array...
For rowdata---Which one I have to take??Any cllecton?? or vector...
After Searching the database(I have search results in hand..but I could n't display those results in the JTable), How to display the data in the JTable..??

Please help me in this regard..

Thomas Fly
Ranch Hand

Joined: Sep 09, 2002
Posts: 164
Why not use JTable(Object[][] rowData, Object[] columnNames) to get something working?

Fly by Night Consultants<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr><i>I climbed on the back of a giant albatross<br />which flew through a crack in the cloud<br />to a place where happiness reigned...<br />all year 'round<br />the music played ever so loudly!</i><p><a href="http://thomasfly.com/songs/Traffic/Hole_in_my_Shoe_qt.htm" target="_blank" rel="nofollow">Hole in My Shoe</a><hr></blockquote>
Stephane Weber
Ranch Hand

Joined: Mar 07, 2002
Posts: 110
Here is how I proceeded :
I passed those arguments to the constructor of my AbstractTableModel implementation :
FieldInfo[] fields
DataInfo[] dbResults
I put the contents of the DataInfo[] into the final Object[][] data variable of the TableModel as Strings.
For the columns names I used the FieldInfo[] (also as Strings). But I then used shorter version of them to make everything fit nicely ...

So in fact, I am using an extension of what Thomas just suggested at the same time
Hope this helps

[ September 17, 2002: Message edited by: Stephane Weber ]
[ September 17, 2002: Message edited by: Stephane Weber ]
jyothi sunke
Ranch Hand

Joined: Sep 11, 2002
Posts: 65
Thanks Thomas & Stephane..
I am able to display the data in the JTable..
Now I have one more doubt..
How do u all selecting perticular flight?? I mean-----After getting search results in a JTable, user has to select one Flight(Itenary).
This is only my idea, not yet implemented. Please guide me if I am going in a wrong direction.
I want to add JRadioButtons to first column of JTable. That means in the first column only JRadioButtons will be there.For my idea to succeed, I have to make whole first column as one entity to get mutually exclusive(ie, user is allowed to select only one flight from search results) effect.
So, user can select perticular flight and can proceed furthur to make a reservation.
If I am correct, give me a clue on-----How to add a component(JRadioButton) to a perticular cell of JTable??
Thanks a lot..
Richard Phen
Ranch Hand

Joined: Apr 27, 2002
Posts: 52
Actually, you may simply add Mouselistener and Keylistener to your JTable and implement some methods to get the information you need, and then when you highlight the flight row you can get some data for booking process.
Hope would help.

jyothi sunke
Ranch Hand

Joined: Sep 11, 2002
Posts: 65
Hi Richard,
Thanks for ur response. But I didn't get u clearly..
So, I need not add JRadioButtons to the table. Is that what u r saying?? With MouseListener & KeyListener work will be done..Is that right!!!
What I want to do is, If user selects the perticular RadioButton, corresponding row will be selected. From that user can proceed...
Please guide me..
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
I suggest you not to try displaying JRadioButton(s) in order for the user to select a flight. It is more work and unnecessary for this assignment and also from the good gui design point of view.
Take a look at JTable.getSelectionModel() and public void addListSelectionListener(ListSelectionListener x) in ListSelectionModel.
jyothi sunke
Ranch Hand

Joined: Sep 11, 2002
Posts: 65
Thank u Prasad...
I will work on that. Thank u once again...
Richard Phen
Ranch Hand

Joined: Apr 27, 2002
Posts: 52
Hi Jyothi,
Yes, the JRadioButtons is unnecessary. For the purpose to react user action with JTable(ie.click to highlight a row), you may add MouseListener & KeyListener. And then, implement some method in it.
public int getAvailableSeats()
int i = table.getSelectedRow();
.........//to get the available amount of seats

Hope would help.
wood burning stoves
subject: How to display values in JTable???
Similar Threads
Editable cells in a JTable
Customizing JTable
JTable ClassCastException...
DataTip for a cell in JTable