dopo vari tentativi ho risolto:
codice:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package graphicComponent; import java.awt.Component; import java.awt.Desktop; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.Map; import java.util.WeakHashMap; import javax.swing.AbstractCellEditor; import javax.swing.JButton; import javax.swing.JOptionPane; import javax.swing.JTable; import javax.swing.table.TableCellEditor; /** * * @author Utente1 */ public class ButtonEditor extends AbstractCellEditor implements TableCellEditor, ActionListener { private JButton pulsante; private String path; public ButtonEditor() { pulsante = new JButton("Lancia File!"); pulsante.addActionListener(this); } @Override public Object getCellEditorValue() { return path; } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { path = (String) value; if (path.equalsIgnoreCase("") || path.equalsIgnoreCase(" ")) { JOptionPane.showMessageDialog(null, "Nessun File Associato", "Errore apertura file", JOptionPane.ERROR_MESSAGE); } return pulsante; } private URI getFileURI(String filePath) { URI uri = null; filePath = filePath.trim(); if (filePath.indexOf("http") == 0 || filePath.indexOf("\\") == 0) { if (filePath.indexOf("\\") == 0) { filePath = "file:" + filePath; filePath = filePath.replaceAll("#", "%23"); } try { filePath = filePath.replaceAll(" ", "%20"); URL url = new URL(filePath); uri = url.toURI(); } catch (MalformedURLException ex) { ex.printStackTrace(); } catch (URISyntaxException ex) { ex.printStackTrace(); } } else { File file = new File(filePath); uri = file.toURI(); } return uri; } public void launchFile(File file) { if (!Desktop.isDesktopSupported()) { return; } Desktop dt = Desktop.getDesktop(); try { dt.open(file); } catch (IOException ex) { launchFile(file.getPath()); } } public void launchFile(String filePath) { if (filePath == null || filePath.trim().length() == 0) { return; } if (!Desktop.isDesktopSupported()) { return; } Desktop dt = Desktop.getDesktop(); try { dt.browse(getFileURI(filePath)); } catch (Exception ex) { ex.printStackTrace(); } } @Override public void actionPerformed(ActionEvent e) { launchFile(path); } }per chiuque dovesse utilizzarlo in futuro.codice:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package graphicComponent; import java.awt.*; import javax.swing.*; import javax.swing.table.*; /** * @version 1.0 11/09/98 */ public class ButtonRender extends JButton implements TableCellRenderer { /** * */ private static final long serialVersionUID = 1L; public ButtonRender() { super(); setOpaque(true); } public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (isSelected) { setForeground(table.getSelectionForeground()); setBackground(table.getSelectionBackground()); } else { setForeground(table.getForeground()); setBackground(UIManager.getColor("Button.background")); } setText("Lancia File"); this.setEnabled(true); return this; } }

Rispondi quotando