Monday, 15 September 2014

java - JFileChooser within a JTable -


All I am trying to create a new component to go inside a JTable are when it is a JFField If a JeffileClosource is clicked on generating, then the user can choose the file system to the browser and select the file which is populated with the path of that field. So far, I have worked at this point that I can fill in the text field in the editor, but when I click on it, the foreskin does not get eggs. Anyone have an idea of ​​what I'm doing wrong here

  extends the public class FileBrowserCellEditor AbstractCellEditor Imposes TableCellEditor, ActionListener {Personal Static last long serialVersionUID = 1L? Private component frame; Button button; JTextField textField; String paths; JFileChooser FC; Preserved static final string EDIT = "edit"; Public FileBrowserCellEditor (Component Frame) {this.frame = frame; TextField = new JTextField (); TextField.setActionCommand (edited); TextField.addActionListener (this); FC = new jefilclosure (); } @ Override public object getCellEditorValue () {return path; } @ Override public component getTableCellEditorComponent (JTable arg0, object arg1, boolean arg2, int arg3, int arg4) {return textField; } @ Override Public Zero ActionPerfed (Action Event e) {// debug system. Outprint LN (EAA Acting Commands ()); If (EDIT.equals (e.getActionCommand ())) // The user has clicked on the cell, so send the dialog textField.setText (path); Fc.showOpenDialog (frame); FireEditingStopped (); // show again the renderer} Else {// the user pressed the "OK" button of the dialog // currentcolor = color selector .getColor (); File file = fc.get selected file (); This.path = file.getAbsolutePath (); Text after "itemprop =" text "> 

Here is a simple cell editor that displays a JFileChooser << code>

/ Code> Double click on the cell:
  import java.awt.Color; Import java.awt.Component; Import java.awt.Font; Import java.io.file; Import javax.swing.DefaultCellEditor; Import javax.swing.JButton; Import javax.swing.JFileChooser; Import javax.swing.JTable; Import javax.swing.JTextField; Import javax.swing.SwingUtilities; Import javax.swing.table.TableCellEditor; Public Square FileChooserCellEditor extends DefaultCellEditor Imposes TableCellEditor {/ ** Click to start the edit * * / personal fixed final integer CLICK_COUNT_TO_START = 2; / ** Editor Component * / Personal Button Button; / ** File Selector * / Private JFileChooser File Selector; / ** selected file * / personal string file = ""; / ** * creator * / public filechasercale editors () {super (new jettextfield); SetClickCountToStart (CLICK_COUNT_TO_START); // Using a pocket button as editor component button = new pocket (); Button.setBackground (Color.white); Button.setFont (button.getFont () deriveFont (Font.PLAIN).); Button.setBorder (zero); // dialog that will be the actual editing filechutzer = new jiffy (); } @ Override public object getCellEditorValue () {return file; } @Override public component getTableCellEditorComponent (JTable table, object value, boolean isSelected, integer row, integer column) {file = value.toString (); SwingUtilities.invokeLater (New Runnable) {Public Zero Run () {fileChooser.setSelectedFile (New file (file));. (If file chooser.showOpenDialog (button) == JFileChooser.APPROVE_OPTION) {file = fileChooser.getSelectedFile () getAbsolutePath ();} FireEditingStopped ();}}); Button.setText (file); Return button; }}   

JTable to add to your .

  yourJTable.getColumnModel () getColumn (yourColumnIndex) .setCellEditor (new file spectrake editor ());    

No comments:

Post a Comment