This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to display values in JTable???

 
jyothi sunke
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
thanks..
 
Thomas Fly
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not use JTable(Object[][] rowData, Object[] columnNames) to get something working?
 
Stephane Weber
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Stephane
[ September 17, 2002: Message edited by: Stephane Weber ]
[ September 17, 2002: Message edited by: Stephane Weber ]
 
jyothi sunke
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
thanks..
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jyothi,
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank u Prasad...
I will work on that. Thank u once again...
 
Richard Phen
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
e.g.
public int getAvailableSeats()
{
int i = table.getSelectedRow();
.........
.........//to get the available amount of seats
}

Hope would help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic