Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static public ImageIcon createIcon(String path) {
- URL imgURL =Main.class.getResource(path);
- if (imgURL != null) {
- return new ImageIcon(imgURL);
- } else {
- System.err.println("File not found " + path);
- return null;
- }
- }
- static class ImageRenderer extends DefaultTableCellRenderer {
- JLabel lbl = new JLabel();
- ArrayList<String> s;
- public ImageRenderer( ArrayList<String> s) {
- this.s=s;
- }
- public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
- boolean hasFocus, int row, int column) {
- lbl.setText((String) value);
- ImageIcon icon = createIcon(s.get(row));
- lbl.setIcon(icon);
- return lbl;
- }
- }
- static JFrame frame = new JFrame();
- static public void open(JFrame f, DefaultTableModel d, JTable t) {
- FileDialog fd =new FileDialog(f, "Wczytaj",FileDialog.LOAD);
- fd.setVisible(true);
- String katalog=fd.getDirectory();
- String plik=fd.getFile();
- BufferedReader br = null;
- try {
- br = new BufferedReader(new FileReader(katalog+plik));
- String line;
- int id_data=0;
- ArrayList<String> s = new ArrayList<String>();
- while ((line = br.readLine()) != null) {
- String[] tmp=line.split("\s+");
- //ImageIcon icon2 = new ImageIcon("java.png");
- Object[] row= { tmp[0],tmp[1],tmp[2] };
- d.addRow(row);
- s.add(katalog+tmp[3]+".png");
- // s[id_data]=s[id_data].replaceAll("", "\");
- //System.out.println(new File(s.get(id_data)).exists());
- // t.setValueAt(icon2, id_data, 3);
- id_data++;
- }
- t.getColumnModel().getColumn(3).setCellRenderer(new ImageRenderer(s));
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- try {
- if (br != null) {
- br.close();
- }
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment