import java.awt.*;
import java.io.File;
import javax.swing.*;
import javax.swing.filechooser.FileSystemView;
import javax.swing.table.*;
public class CustomCellRenderer extends JLabel implements TableCellRenderer
{
private boolean isSelected;
private boolean hasFocus;
private String sText;
private FileSystemView fikus;
/** Creates a new instance of CustomCellRenderer */
public CustomCellRenderer() {
fikus = FileSystemView.getFileSystemView();
}
public Component getTableCellRendererComponent(JTable table, Object
value, boolean isSelected, boolean hasFocus, int row, int column) {
sText = (String)value;
this.isSelected = isSelected;
this.hasFocus = hasFocus;
if(isSelected)
setForeground(Color.blue);
else
setForeground(Color.black);
if(hasFocus)
setForeground(Color.cyan);
//tworze obiekt file
File file = new File(sText);
File nowy = new File(file.getAbsolutePath());
setIcon(fikus.getSystemIcon(nowy));
//setIcon(fikus.getSystemIcon(file));
return this;
}
public void paint(Graphics g) {
super.paint(g);
Color bColor;
if(isSelected)
bColor = Color.cyan;
else
bColor = Color.blue; //white?
if(hasFocus)
bColor = Color.red;
g.setColor(bColor);
g.fillRect(0,0,getWidth()-1, getHeight()-1);
//super.paint(g);
}
}
File file = new File(sText);
sText - reprezentuje 162.JPG
W linijce tworze file z pelna sciezka bo chyba musi byc pelna sciezka a nie
tylko nazwa i roszerzenie
File nowy = new File(file.getAbsolutePath());
setIcon(fikus.getSystemIcon(nowy));
ale pojawia sie wyjatek:
FileSystemView.getShellFolder: f=C:\Documents and
Settings\Jarek\MenadzerPlikow\162.JPG
java.io.FileNotFoundException
at sun.awt.shell.ShellFolder.getShellFolder(ShellFolder.java:234)
at
javax.swing.filechooser.FileSystemView.getShellFolder(FileSystemView.java:486)
at
javax.swing.filechooser.FileSystemView.getSystemIcon(FileSystemView.java:182)
przecież ten plik istnieje?Co to moze byc?
Pozdrawiam
Jarek
Nie pełna tylko absolutna. Może być sama nazwa i rozszerzenie. Albo
ścieżka względna.
> ale pojawia sie wyjatek:
> FileSystemView.getShellFolder: f=C:\Documents and...
^^
A to co?
Nie może ewidentnie znaleźć pliku w ścieżce. Podaj ją poprawinie.
Pozdrawiam
Marek
--
# You can't run away. Everyone's connected.
# Marek Puchalski
# Proud linux user: 409592
Pozdrawiam
Jarek