File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable problems.

 
Felix Erendi
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody help me with my struggles with
JTable. I'm using the model-view-control pattern
and I have implemented the search and the data
presentation, in a JTable, part of the GUI.
I have added a JTextFiled for chair bookins to
each row of the JTable but I don't know how to add
an actionlistner to them. And the number entered
does not "stick" when focus is moved from that
cell?
/Felix
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could change your GUI to have one JTextfield underneath the JTable, so that the user selects a record then enters the number in the TextField below.
Now for adding ActionListeners, I always suggest a Hook method for an outside class to be able to call that will Hook that class with the Object on the GUI that you want to add this ActionListener to.
FOr example there is a public method in the gui called AddBookingTextFieldListener, or some better name than that. Actually check out the code below for a good example of a Hook method and good name.

Now the above is to allow me to add an ActionListener to a JButton on my GUI. personally I didn't have any for the JTextField that I had since I was only concerned with button actions.
then you Controller class can create an ActionListener and pass it to this GUI method.
like

Hope that helps
Mark
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11833
181
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Felix,
If you are really set on having data entry next to each row in the table then you could add a column to the table in the View before creating the TableModel - you would have to create your own TableModel so that you could specify that the extra column was editable.
The Sun tutorials show how to make the table editable, and how to limit the editing to various cells.
It is very easy, and has the advantage that it allows two rows to be booked simultaneously. For the FBNS system this could mirror real life better - most people book a return flight rather than 2 one way fares.
I went down this path originally, and found it very easy, but I decided against it because I could see potential problems with expandability - say if FBNS decided to have adult and child fares, the screen would have to have another column entered (and eventually another, and another ....) or the column would have to be removed which would dramatically change the way the user interacted with the system. This goes against the requirement:
Your user interface should be designed with the expectation of future functionality enhancements, and it should establish a control scheme that will support this with minimal disruption to the users when this occurs.

Regards, Andrew
 
Bigwood Liu
Ranch Hand
Posts: 240
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Andrew. search something about TableModel maybe help. it is clear and easy.
 
Felix Erendi
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Mark and Andrew!
After considering your answers, I decided to go for the JTextField outside of the table.
/Felix
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic