Customizing JFIleChooser

Hi,
I have an issue with JFileChooser. My application uses a JFileChooser to select a folder location. I need to customize the JFileChooser so that the user shud be able to select folders and only view files not select it. He shud be allowed to select/open only folders, not the files within it.
Thanks

Read the API docs... there's an option for DIRECTORIES_ONLY

Similar Messages

  • Get state of checkbox in customized JFileChooser

    I have built a custom JFileChooser that displays a JCheckBox as an accessory component.
    // build an accessory panel for the file chooser
    JPanel accesoryPanel = new JPanel(new GridLayout(2, 1));
    accesoryPanel.setBorder(BorderFactory.createTitledBorder("Export options"));
    JCheckBox checkbox = new JCheckBox ("Copy symbol files", isCopySymbolsDuringExportEnabled);
    accesoryPanel.add (checkbox);
    JFileChooser fc = new JFileChooser("c:\\temp");
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fc.setAccessory(accesoryPanel);
    int returnVal = fc.showDialog(null, "Choose export directory");
    exportDirectory = fc.getSelectedFile().getPath();
    How do I refer to the checkbox to see whether the user checked it or not?
    -Phil

    Nevermind. As soon as I hit send I realized I can simply do
    isCopySymbolsDuringExportEnabled= checkbox.isSelected();

  • Help with custom JFileChooser

    Hello everyone,
    I would like to customize JFileChooser to display a panel with some text above the folder browse section.
    Is this possible... if so, could anyone provide some sample code on how to get this started?

    I'm afraid you're on your own. Noone has [ever done something like that before|http://www.google.com/search?q=customizing jfilechooser].

  • Custom JFileChooser painting

    Hi all, still new at swing and customizing their look and have a few questions regarding customizing the painting of a JFileChooser. First I would like to change the gradients of the buttons. Is this possible? Usually I have gone about changing a components paintComponent method(as below). But I have no idea how to do this when trying to set the painting of a child component. Probably possible to loop also through the child components and find the buttons, but then what?
    Second I had used a recursive method to set child jpanel components of a JOptionPane to set them opaque and allow the JOptionPanes new custom paint to show through. I tried to apply that to the JFileChooser and am left with an area at the bottom and left that are the default colors.
    I have added statement to also change any JComponent to setOpaque(false), but this doesnt help. Any suggestions or help would be appreciated.
    heres the sample and thanks again.
    package filechoosertest;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.GradientPaint;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Insets;
    import java.awt.RenderingHints;
    import javax.swing.JComponent;
    import javax.swing.JFileChooser;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    public class TestFileChooser extends JFileChooser{
        private Color startColor1 = new Color(255,255,255);
        private Color endColor1 = new Color(207,212,206);
         public static void main(String[] args) {
            // TODO code application logic here
            SwingUtilities.invokeLater(new Runnable(){
                public void run() {
                 TestFileChooser tfc = new TestFileChooser();
                 tfc.showOpenDialog(null);
        public TestFileChooser(){
            super();
             mySetOpaque(this);
         protected void mySetOpaque(JComponent jcomp) {
            Component[] comps = jcomp.getComponents();
            for (Component c : comps) {
                System.err.println("Component class " + c.getClass().getName());
                if (c instanceof JPanel) {
                    System.err.println("Setting opaque");
                    ((JPanel) c).setOpaque(false);
                    mySetOpaque((JComponent) c);
         public void paintComponent(Graphics g) {
            Dimension dim = getSize();
            Graphics2D g2 = (Graphics2D) g;
            Insets inset = getInsets();
            int vWidth = dim.width - (inset.left + inset.right);
            int vHeight = dim.height - (inset.top + inset.bottom);
            paintGradient(g2, inset.left,
                    inset.top, vWidth, vHeight, dim.height);
             private void paintGradient(Graphics2D g2d, int x, int y,
                int w, int h, int height) {
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
            GradientPaint GP = new GradientPaint(0, h * 3 / 4, startColor1, 0, h, endColor1, false);
            g2d.setPaint(GP);
            g2d.setPaint(GP);
            g2d.fillRect(1, 1, w, h);
    }

    Your problem, I think, is that you are not setting the opaque on JPanels nested within other JPanels. a small recursive routine should fix this:
      public MyOptionPane(Object message, int messageType, int optionType,
          Icon icon, Object[] options, Object initialValue) {
        super(message, messageType, optionType, icon, options, initialValue);
        mySetOpaque(this);
      private void mySetOpaque(JComponent jcomp)
        Component[] comps = jcomp.getComponents();
        for (Component c : comps) {
          if (c instanceof JPanel) {
            ((JPanel)c).setOpaque(false);
            mySetOpaque((JPanel)c);
      }

  • Custom JFileChooser

    Hallo,
    I created a custom filechooser dialog by putting a JFileChooser component on a panel of my dialog. I need to have a SAVE dialog. I did set the type to SAVE_DIALOG, did hide the control buttons...
    When I do not select any file but write the name of the file in the textfield (of the JFileChooser component) I cannot access the file by getSelectedFile(), because this is null.
    If i do not hide the control buttons and click to the approve button, I can access the file with getSelectedFile().
    What happens, when the approve button is pressed? And what do I need to do to get the filename?
    Thanks a lot.
    Steffen

    Some code would be appreciated, otherwise it's more difficult to recreate your scenario. Keep the code as minimal as can be though.
    Cheers.

  • Customizing JFileChooser using Synth

    I'm creating custom Look&Feel using synth, and I'm having problems with the toggle buttons which commute between list view an table view. I'm unable to set the inset margins for thos buttons,
    I've tried to use:
         <property key="JToggleButton.margin" type="insets" value="4 4 4 4"/>
    and
         <property key="ToggleButton.margin" type="insets" value="4 4 4 4"/>
    with no success.
    Any ideas ?

    user1285890 wrote:
    Which thread ?The first thread you started: Splash screen in stand alone FXML application
    db

  • Customizing JFileChooser (File Size) Need Help

    Can you help me with this. I want to customize my JFileChooser. I'm in a Windows environment so the file view that I see is same with that of the option pane of windows. What I would like to do is make the size that is viewed from the screen from ##KB to specific bytes size. (ex. 34421245). Can someone help me on this. I was able to see some codes on the net but those codes are not straightforward. They override the BasicFileChooserUI. Can someone help me on this. I don't want to override the BasicFileChooserUI instead I want to use the JFileChooser and change the size from ###KB to bytes. Thank you. ^_^

    Hi Rachel,
    My best idea for that is to load the swf files externally, so
    that each page is a different swf. A technique like this would be
    very simple and quick to use, because it only loads what you need
    when you need it.
    For example, you'd set the intro page to load right away, and
    then when you select "At Work" the intro page unloads and is
    replaced by the at work page.
    Another thing you may want to consider is holding the images
    in an xml file, and then using some basic flash/xml intergration to
    load each image as it's called. That way each image isn't stored in
    the flash file causing it to increase in size, and instead is
    actually loaded externally which is must faster.
    There are some great tutorials, if you're intrested, on how
    to do both of these at:
    http://www.kirupa.com/
    Hope I helped some!

  • JFileChooser and thumbnail view

    How can I implement a custom JFileChooser that show thumbnail of image files such as TIFF and PNG?
    As before, I used FileDialog on Windows XP for this purpose.
    But FileDialog does not support multi file selection and file name filters.
    I tried to implement custom FileView. (getIcon() method).
    But it was so slow and strange.
    Could you guys give me a advice on this problem?

    Hi Dhiva,
    materialized view is essentially a table that is produced from other tables based on a query. It's results are physically stored in the database and are refreshed either when the user requests ('on-demand refresh') or after commit.
    A simple view is just a query stored in the database. It's results are not stored anywhere, they're calculated and returned to the user only when the view is queried.
    Best regards,
    Nikolay

  • Fine-tuning the appearance of JFileChooser

    I have what I hope is a simple question:
    I'm creating a customized JFileChooser. One of the cool things it does is it displays its own custom icons for the files. These icons are a bit bigger than the standard icons for my look-and-feel (Linux default LandF, whatever that is, in Java 1.5). These icons are about 45 pixels high. They look GREAT when viewing in the "icon" view, but when the user switches to the "list" view, they draw on top of eachother. Somehow JFileChooser doesn't know to leave more space.
    Any suggestions on this?
    And the other question, which I'm sure is a FAQ but I can't find it: I also have a file filter on this JFileChooser, and yet it gives the user the option of changing to "view any file type". Is there a way to turn that off? I really want to constrain what my users are doing.
    Thanks

    hi leena,
    Look into these threads...
    https://www.sdn.sap.com/irj/sdn/thread?threadID=119605
    https://www.sdn.sap.com/irj/sdn/thread?threadID=101325
    Also see,
    <a href="https://websmp103.sap-ag.de/~form/sapnet?_SHORTKEY=00200797470000073623&_OBJECT=011000358700001480992005E">this link</a>
    https://media.sdn.sap.com/public/eclasses/bwp04/PortalTuning_files/Default.htm
    Regs,
    jaga
    Message was edited by: jagadeep sampath

  • JFileChooser file select by doubleclick

    To improve the user friendliness of my custom JFileChooser dialog, I want the user to be able to doubleclick on the file he wants to open, instead of having to click the file and then on open.
    I thought it would be the simplest thing, but have not found any solutions. Adding a mouselistener to the JFileChooser will not return mouse events inside the file list itself, and the PropertyChangeListener does not respond to a double click action either.
    Any help would be greatly appreciated! :-)

    Works automatically in the JFileChoosers in my app (Win2K Pro). Could be the l&f or you are overriding the default mouse actions. A look at the code may help.
    Robert Templeton

  • JFilehooser open button event trigger

    Hi guys;
    I've written a customized JFileChooser .
    i'm using the propertyChangeListener() overriden method to implement the importing of a file...however I found it a little bit annoying that the importing is fired with a simple click on selected file...
    what i need is that the import() method is only triggered when the open button of the filechooser is clicked...
    Is it possible to do that without much changing my code ?
    How can I implement this ?
    thanks for helping !
    here is my code:
    import javax.swing.*;
    import java.beans.*;
    import java.io.File;
    * @author E.othman
    * Class for Loading seleted File
    * FileLoader.java is  used by FileChooser.java. */
    public class FileLoader extends JComponent implements PropertyChangeListener {
        static boolean update = false;
        static File file = null;
        static JFileChooser fc;
        static JFrame frame;
        JavaUI ui;
          * constructor
          * @author E.othman
          * @return null
          * @param  JavaUI reference to Main UI class , JFileChooser
        public FileLoader(JFileChooser fc,JavaUI ui) {
             FileLoader.fc=fc;
            this.ui=ui;
            fc.addPropertyChangeListener(this);
          * Method for actual task of loading and Importing a ppt Presentation.
          * Instantiates a PowerPointConverter objet and starts its Thread.
          * @author E.othman
          * @return void
          * @param  JavaUI reference to Main UI class
          * @see    PowerPointConverter
        public  static void importFile(JavaUI ui) {
            if (file == null) return;
                 String extension = Utils.getExtension(file);
                 if (extension != null) {
                   if (!extension.equals(Utils.ppt)){
                        JOptionPane.showMessageDialog(frame,file.getName()+ " Is Not a Valid PowerPoint File !","Select File Error",JOptionPane.ERROR_MESSAGE);
                        return;
            if( !file.exists()){
                 JOptionPane.showMessageDialog(frame,"File \""+file.getName()+ "\"  Doesn't Exists !","Select File Error",JOptionPane.ERROR_MESSAGE);
                 return;
                fc.approveSelection();
                try{
                     PowerPointConverter a = new PowerPointConverter(ui);
                     a.setFile(file.getPath());
                         a.start();
               }catch(Exception e){
                    JOptionPane.showMessageDialog(frame,e.getMessage(),"Error Importing Presentation",JOptionPane.ERROR_MESSAGE);
                 return;
        public void propertyChange(PropertyChangeEvent e) {
             update = false;
             String prop = e.getPropertyName();
            //If the directory changed, don't import.
            if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(prop)) {
                file = null;
                update = true;
            //If a file became selected, find out which one.
            } else if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(prop)) {
                file = (File) e.getNewValue();
                 update = true;
            //do import.
            if (update) {
               if (isShowing()) {
                    importFile(ui);
    }

    The propertyChange Listener is for the currently
    selected file, and is indeed updated on every click.
    What you want is code along the lines of:
    if  (myFileChooser.showDialog(parentFrame,
    "Import")==JFileChooser.APPROVE_OPTION)
    //..your import code
    }I.e. from the place where you create and call the
    file chooser dialog,
    that's where you perform the import action after it's
    been confirmed by the user.Thanks for the hint !
    I can now have my functionality working fine !
    Just another question please : I still don't want the importing to be triggered if the selected file is double-clicked . I got rid of single click problem. is it possible to make the importing launched only if i clicked the open button ? (disable double-clicking ?)
    thanks for your time and precious help !

  • Restrict FileSystemView to a Directory

    Trying to force my JFileChooser to restrict to only one directory so that users cannot navigate the file system. This custom JFileChooser will be used for playing or deleting files. Any sample code for restricting FileSystemView to a directory, much appreciated.

    I'm facing a similar problem i think.
    I want to initialize the JfileChooser with selected drives (obtained by a net use command).
    I subcalsses the FileSystemView.
    In the getRoots() I call the createFileSystemRoot() for each drive I want as root.
    (i tried with "new File" or by getting a file from the createFileObject() )
    In the getParent(), I check the user doesn't try to go uppser tha, the roots returning the specified root if needed
    In the getHome(), I set a directory wich is or is under one of the sp�cified roots.
    The result is : the JcomboBox only displays the roots specified, the home button doesn't use the OS root anymore, the level up button is restricted and doen't go outside the roots specified.
    The only problem i'm not able to sove :
    The JcomboBox is not refresh correctly.
    The standard behaviour is :
    the combobox displays the curent folder name, when expadning the combo box, it dsiplays all the rrots and expand the hierachy from the root of the current folder to the folder
    eg :
    root1
    folder1
    folder2
    In my case, the current forlder is correctly displayed in the combo box but when I click on it to expand it, I only see the roots ... not the sub folders as explained in the standard behaviour.
    Help is welcome...

  • ImageObserver and rescaled image

    Hi,
    I got a custom JFileChooser, where the user can see image previews.
    The little problem is, for large images, the rescale-method takes a few seconds to show the
    image on the custom view component. How can i(in general for unscaled pictures too) show the
    current status of the image(maybe during rescaling).
    regards.
    Olek

    ok, so now I have:
    public class Goomba implements java.awt.image.ImageObserver
    That gives me an error that: Goomba should be declared abstract; it does not define
    imageUpdate(java.awt.image, int, int, int, int, int) in Goomba
    So I tried putting imageUpdate(gi, 0, pos_x, pos_y, 50, 50) .........and I still get the same error.
    If this helps, heres the code in question:
    import java.applet.*;
    import java.awt.*;
    import java.util.*;
    import java.net.*;
    public class Goomba implements java.awt.image.ImageObserver
         private int pos_x;
         private int pos_y;
         private int x_speed;
         private int first_x;
         private int first_y;
         private int maxspeed;
    Image gi;     
         private final int x_leftout = 25;
         Player player;
    //calls this everytime we want a new goomba
    // x is the x position
    // y is the y position
    // vx is the speed
    // player is the player
    // goomba_image is the actual image of the goomba
         public Goomba (int x, int y, int vx, Player player, Image goomba_image)
              pos_x = x;
              pos_y = y;
              first_x = x;
              first_y = y;
              x_speed = vx;          
    gi = goomba_image;
              this.player = player;
    //--------------------cut out the rest of the code for Goomba ---------------------
         public void DrawGoomba(Graphics g)
    //tried this when it gave me the imageUpdate error:
    //imageUpdate(gi, 0, pos_x, first_y, 50, 50);
              g.drawImage(gi, pos_x, first_y, 50, 50, this);
    }

  • Ordering of files once a custom FileView has been set in a JFileChooser.

    My end user has a requirement for custom icons in a JFileChooser. I have created a custom FileView but find that the ordering of files and directories is different to the order presented in the default FileView.
    For example in the default FileView, the directories are listed first and the files next.
    In my custom FileView, I see that the files and directories are listed in ascending alphabetical order, so that files and directories are all listed together.
    Attempting to alter the order using a custom FileSystemView with the method public File[] getFiles(File dir,boolean useFileHiding) where the returned file array is in the required order, is still defeated.
    I would be grateful for some assistance.

    I've tried it, but it will only accept an ID in the new format, i.e., an email address.  The old ID was a 7 character alpha only.

  • Strange behavior in JTable using JFileChooser as custom editor

    I have an application that I am working on that uses a JFileChooser (customized to select images) as a custom editor for a JTable. The filechooser correctly comes up when I click (single click) on a cell in the table. I can use the filechooser to select an image. When I click on the OPEN button on the filechooser, the cell then displays the editor class name.
    I have added prints to the editor methods and have determined that editing is stopped before the JTable adds the listener. I have looked at the code and have searched doc for examples but have not found what I am doing wrong. Can anyone help?
    I configured the table editor as follows:
    //Set up the editor for the Image cells.
    private void setUpPictureEditor(JTable table) {
    table.setDefaultEditor(String.class, new PictureChooser());
    Below is the code for the JTable editor that I am using:
    package com.board;
    import java.io.*;
    import java.util.Vector;
    import java.util.EventObject;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.JFileChooser;
    import javax.swing.JPanel;
    import javax.swing.table.TableCellEditor;
    import javax.swing.event.CellEditorListener;
    import javax.swing.event.ChangeEvent;
    public class PictureChooser extends JLabel implements TableCellEditor
    boolean DEBUG = true;
    int line=0;
    static private String newline = "\n";
    protected boolean editing;
    protected Vector listeners;
    protected File originalFile;
    protected JFileChooser fc = new JFileChooser("c:\\java\\jpg");
    protected File newFile;
    public PictureChooser()
    super("PictureChooser");
    if (DEBUG)
         System.out.println(++line + "-PictureChooser constructor");
         listeners = new Vector();
         fc.addChoosableFileFilter(new ImageFilter());
         fc.setFileView(new ImageFileView());
         fc.setAccessory(new ImagePreview(fc));
    private void setValue(File file)
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.setValue method");
         newFile = file;
    public Component getTableCellEditorComponent(JTable table,
                                  Object value,
                                  boolean isSelected,
                                  int row,
                                  int col)
    if (DEBUG)
         System.out.println(line + "-PictureChooser.getTableCellEditorComponent row:" + row + " col:" + col + " method");
         fc.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                   String cmd = e.getActionCommand();
                   System.out.println(++line + "-JFileChooser.actionListener cmd:" +
                                       cmd);
                   if (JFileChooser.APPROVE_SELECTION.equals(cmd))
                        stopCellEditing();
                   else
                        cancelCellEditing();
         //editing = true;
         //fc.setVisible(true);
         //fc.showOpenDialog(this);
         int returnVal = fc.showOpenDialog(this);
         if (returnVal == JFileChooser.APPROVE_OPTION)
         newFile = fc.getSelectedFile();
         table.setRowSelectionInterval(row,row);
         table.setColumnSelectionInterval(col,col);
         return this;
    // cell editor methods
    public void cancelCellEditing()
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.cancelCellEditing method");
         fireEditingCanceled();
         editing = false;
         fc.setVisible(false);
    public Object getCellEditorValue()
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.getCellEditorValue method");
         return new ImageIcon(newFile.toString());
    public boolean isCellEditable(EventObject eo)
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.isCellEditable method");
         return true;
    public boolean shouldSelectCell(EventObject eo)
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.shouldSelectCell method");
         return true;
    public boolean stopCellEditing()
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.stopCellEditing method");
         fireEditingStopped();
         editing = false;
         fc.setVisible(false);
         return true;
    public void addCellEditorListener(CellEditorListener cel)
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.addCellEditorListener method");
         listeners.addElement(cel);
    public void removeCellEditorListener(CellEditorListener cel)
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.removeCellEditorListener method");
         listeners.removeElement(cel);
    public void fireEditingCanceled()
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.fireEditingCanceled method");
         setValue(originalFile);
         ChangeEvent ce = new ChangeEvent(this);
         for (int i=listeners.size()-1; i>=0; i--)
         ((CellEditorListener)listeners.elementAt(i)).editingCanceled(ce);
    public void fireEditingStopped()
    if (DEBUG)
         System.out.println(++line + "-PictureChooser.fireEditingStopped method");
         ChangeEvent ce = new ChangeEvent(this);
         for (int i=listeners.size()-1; i>=0; i--)
    System.out.println(++line + "-PictureChooser listener " + i);
         ((CellEditorListener)listeners.elementAt(i)).editingStopped(ce);

    try this code. it work fine.
    regards,
    pratap
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    import java.io.*;
    public class TableDialogEditDemo extends JFrame {
         public TableDialogEditDemo() {
              super("TableDialogEditDemo");
              MyTableModel myModel = new MyTableModel();
              JTable table = new JTable(myModel);
              table.setPreferredScrollableViewportSize(new Dimension(500, 70));
              //Create the scroll pane and add the table to it.
              JScrollPane scrollPane = new JScrollPane(table);
              //Set up renderer and editor for the Favorite Color column.
              setUpColorRenderer(table);
              setUpColorEditor(table);
              //Add the scroll pane to this window.
              getContentPane().add(scrollPane, BorderLayout.CENTER);
              addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
                        System.exit(0);
         private void setUpColorRenderer(JTable table) {
              table.setDefaultRenderer(File.class, new PictureRenderer(true));
         //Set up the editor for the Color cells.
         private void setUpColorEditor(JTable table) {
              table.setDefaultEditor(File.class, new PictureChooser());
         class PictureRenderer extends JLabel     implements TableCellRenderer {
              Border unselectedBorder = null;
              Border selectedBorder = null;
              boolean isBordered = true;
              public PictureRenderer(boolean isBordered) {
                   super();
                   this.isBordered = isBordered;
                   setOpaque(false);
                   setHorizontalAlignment(SwingConstants.CENTER);
              public Component getTableCellRendererComponent(
                                            JTable table, Object value,
                                            boolean isSelected, boolean hasFocus,
                                            int row, int column) {
                   File f = (File)value;
                   try {
                        setIcon(new ImageIcon(f.toURL()));
                   catch (Exception e) {
                   e.printStackTrace();
                   return this;
         class MyTableModel extends AbstractTableModel {
              final String[] columnNames = {"First Name",
                                                 "Favorite Color",
                                                 "Sport",
                                                 "# of Years",
                                                 "Vegetarian"};
              final Object[][] data = {
                   {"Mary", new Color(153, 0, 153), "Snowboarding", new Integer(5), new File("D:\\html\\f1.gif")},
                   {"Alison", new Color(51, 51, 153), "Rowing", new Integer(3), new File("D:\\html\\f2.gif")},
                   {"Philip", Color.pink, "Pool", new Integer(7), new File("D:\\html\\f3.gif")}
              public int getColumnCount() {
                   return columnNames.length;
              public int getRowCount() {
                   return data.length;
              public String getColumnName(int col) {
                   return columnNames[col];
              public Object getValueAt(int row, int col) {
                   return data[row][col];
              public Class getColumnClass(int c) {
                   return getValueAt(0, c).getClass();
              public boolean isCellEditable(int row, int col) {
                   if (col < 1) {
                        return false;
                   } else {
                        return true;
              public void setValueAt(Object value, int row, int col) {
                   data[row][col] = value;
                   fireTableCellUpdated(row, col);
         public static void main(String[] args) {
              TableDialogEditDemo frame = new TableDialogEditDemo();
              frame.pack();
              frame.setVisible(true);
    import java.awt.Component;
    import java.util.EventObject;
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.io.*;
    public class PictureChooser extends JButton implements TableCellEditor, ActionListener {
         protected EventListenerList listenerList = new EventListenerList();
         protected ChangeEvent changeEvent = new ChangeEvent(this);
         private File file;
         public PictureChooser() {
              super("");
              setBackground(Color.white);
              setBorderPainted(false);
              setMargin(new Insets(0,0,0,0));
              addActionListener(this);
         public Component getTableCellEditorComponent(JTable table, Object value,
                                                 boolean isSelected, int row, int column) {
         File f = (File)value;
         try {
              setIcon(new ImageIcon(f.toURL()));
         catch (Exception e) {
              e.printStackTrace();
         return this;
         public void actionPerformed(ActionEvent e)
         JFileChooser chooser = new JFileChooser("d:\\html");
         int returnVal = chooser.showOpenDialog(this);
              if(returnVal == JFileChooser.APPROVE_OPTION) {
                   file = chooser.getSelectedFile();
                   System.out.println("You chose to open this file: " + chooser.getSelectedFile().getName());
                   fireEditingStopped();
              else
                   fireEditingCanceled();
         public void addCellEditorListener(CellEditorListener listener) {
         listenerList.add(CellEditorListener.class, listener);
         public void removeCellEditorListener(CellEditorListener listener) {
         listenerList.remove(CellEditorListener.class, listener);
         protected void fireEditingStopped() {
         System.out.println("fireEditingStopped called ");
         CellEditorListener listener;
         Object[] listeners = listenerList.getListenerList();
         for (int i = 0; i < listeners.length; i++) {
              if (listeners[i] == CellEditorListener.class) {
              listener = (CellEditorListener) listeners[i + 1];
              listener.editingStopped(changeEvent);
         protected void fireEditingCanceled() {
         CellEditorListener listener;
         Object[] listeners = listenerList.getListenerList();
         for (int i = 0; i < listeners.length; i++) {
              if (listeners[i] == CellEditorListener.class) {
              listener = (CellEditorListener) listeners[i + 1];
              listener.editingCanceled(changeEvent);
         public void cancelCellEditing() {
         System.out.println("cancelCellEditing called ");
         fireEditingCanceled();
         public boolean stopCellEditing() {
         System.out.println("stopCellEditing called ");
         fireEditingStopped();
         return true;
         public boolean isCellEditable(EventObject event) {
         return true;
         public boolean shouldSelectCell(EventObject event) {
         return true;
         public Object getCellEditorValue() {
              return file;

Maybe you are looking for

  • How do you change the mail address of the AppleID in App Store?

    I have my email address (used as AppleID)  changed at iTune store. Now when I log on App Store, it asks for password with dialog box already carrying my previous email address as AppleID. Now I cannot log into App Store. Help? I think I have to chang

  • Quick time 7.7.3 crash?

    When I go onto Sportstec's website and go onto their knowledge base to look at a tutorial on a upgrade for software i already have  I get a 7.7.3 quick time crash comes up just below my browser. Its never happened before. Please Help?

  • Without SLAT - Android emulators (for App development) will run OK

    processor  : http://ark.intel.com/products/33922/Intel-Core2-Quad-Processor-Q9300-6M-Cache-2_50-GHz-1333-MHz-FSB model:  // RAM 8GB    64 bit OS HP Pavilion Elite m9372.gr Desktop PC    2008-2009 part_number : FZ110AA-B1A Tried run WP8.1 emulators bu

  • Change of principal switch

    Hello, We have to fabrics with MDS9513 directors. Yesterday we got a change of principal switch message and the VSANs notice on one of the fabrics. Everything continued to work normally. Is this a normal occurance? What could be the reason? Is it a s

  • Ipod doesn't import after moving internal HDD

    Ok , I have a Ipod classic and running windows XP Sp3. I was running out of room on the internal HDD , so fitted a new additional HDD and moved all my data to the drive (F drive). I did this following the instructions very carefully via Edit-Preferen