wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes TableModelEvent question: fires AFTER user has navigated away from cell, not what I need Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "TableModelEvent question: fires AFTER user has navigated away from cell, not what I need" Watch "TableModelEvent question: fires AFTER user has navigated away from cell, not what I need" New topic
Author

TableModelEvent question: fires AFTER user has navigated away from cell, not what I need

J Westland
Ranch Hand

Joined: Apr 06, 2009
Posts: 40
Hello -

Another day in Java land. I am working on a little Swing/SQL application to hone my skills. It is for keeping data and pictures of chickens (I keep chickens)

It loads the data from the MySQL into a table using DefaultTableModel (will implement my own model later, on the ToDo list)

Now users can also show a picture of the chicken as filepaths are very annoying to type, I want to use a JFileChooser so users can select the picture, then save path into DB.

So I "bound" a TableModelListener to the table, once a TMEvent fires I ask it to check for the row/column if these match the picture cell (selection of course set to single_selection) it starts the JFileChooser. However, this only starts AFTER a users has navigated away or hit "enter" in the table text cell that holds picture data. I want it to start right away, "on click".

Is there a simple way to do what I want, or will it be Swings and roundabouts? If there's a class/interface or combination thereof, just say which ones to use and I will try to figure out the rest myself.

Thanks for reading

See code below.



Woohoo passed SCJP 1.6, that's the theory exam passed now for the practice ;)
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2155
    
    7
If you are saying that the user can select any image from anywhere on the file system, then using a JFileChooser may be the best approach. However instead of using a TableModelListener you will need to use a "custom editor" to display the file chooser. Read the JTable API and follow the link to the Swing tutorial where you will find an example that display a JColorChooser as the editor. You should be able to customize the code for the file chooser.

If you are limiting the user to select an image from a given directory, it may be easier to use a combo box as the editor and to preload all the images into the combo box. Then the user can just select the image from the combo box.
J Westland
Ranch Hand

Joined: Apr 06, 2009
Posts: 40
Ah makes sense, don't use the table but use the component that displays the image to "listen" and open the JFileChooser.

That will work, thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TableModelEvent question: fires AFTER user has navigated away from cell, not what I need
 
Similar Threads
Help with using JCheckBox in JTable to return a value in another column
JTable displaying input data onto console
Having problem in resetting the value of JTable
How to set focus on submit button on press of enter key
Update database by editing the cells in JTable