Bonjour,

Malgré mes nombreuses recherche je ne trouve pas d'ou viens le problème du chargement des images sur un toolsbar.

Les chemins d'accès des images sont corrects. Toutefois les attributs "width" et "heigth" de l'image sont à 0.

voici le code (TestActions.java):
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
 
/**
 * 
 */
package com.complex.ui;
 
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
 
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
 
/**
 * @author Sébastien Serpaud
 *
 */
public class TestActions {
 
	/**
         * 
         */
	private static final long serialVersionUID = 18862990943464100L;
 
	private DemoAction action[];
 
	/**
         * 
         */
	@SuppressWarnings("serial")
	public TestActions() {
 
		action = new DemoAction[6];
 
		action[0] = new DemoAction("Plot Magnitude", 'M', 
				createImageIcon("com/complex/lib/icons/magnitude.ico"));
		action[1] = new DemoAction("Plot Magnitude in dB", 'B', 
				createImageIcon("com/complex/lib/icons/db.ico"));
		action[2] = new DemoAction("Plot Phase", 'P', 
				createImageIcon("com/complex/lib/icons/phase.ico"));
		action[3] = new DemoAction("Plot Phase in degree", 'D', 
				createImageIcon("com/complex/lib/icons/phasedegree.ico"));
		action[4] = new DemoAction("Plot Real Part", 'R', 
				createImageIcon("com/complex/lib/icons/re.ico"));
		action[5] = new DemoAction("Plot Imaginary Part", 'I', 
				createImageIcon("com/complex/lib/icons/im.ico"));
	}
 
	public void initMenu(JMenu menu) {
		for (int i = 0; i < action.length; i++)
			menu.add(action[i]);
	}
 
	public void initToolBar(JToolBar toolBar) {
		for (int i = 0; i < action.length; i++)
			toolBar.add(action[i]);
	}
 
	private ImageIcon createImageIcon(String path) {
        java.net.URL imgURL = this.getClass().getClassLoader().getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println(this.getClass().getName() + " : fichier non trouve : " + path);
            return null;
        }
    }
 
	private class DemoAction extends AbstractAction {
		/**
                 * 
                 */
		private static final long serialVersionUID = -8785245616631770805L;
 
		public DemoAction(String text, char shortcutKey, ImageIcon icon) {
			super(text, icon);
			putValue(SHORT_DESCRIPTION, text);
			putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(shortcutKey,
					Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
		}
 
		public void actionPerformed(ActionEvent a) {
			String name = (String) getValue(NAME);
 
			System.out.println(name);
		}
	}
}
et le program test (Test.java):
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
 
/**
 * 
 */
package com.complex.ui;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.HeadlessException;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
 
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JToolBar;
 
/**
 * @author Sébastien Serpaud
 *
 */
public class Test extends JFrame {
 
	/**
         * 
         */
	private static final long serialVersionUID = -6041236038996063149L;
 
	/**
         * @throws HeadlessException
         */
	public Test()  {
		super("Test Actions");
		this.setPreferredSize(new Dimension(600, 480));
 
		this.setJMenuBar(new JMenuBar());
 
		TestActions formatActions = new TestActions();
 
		JMenu menu = new JMenu("Format");
		formatActions.initMenu(menu);
		this.getJMenuBar().add(menu);
 
		JToolBar toolBar = new JToolBar("Format");
		formatActions.initToolBar(toolBar);
		this.getContentPane().add(toolBar, BorderLayout.NORTH);
 
 
		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent evt) {
				System.exit(0);
			}
		});
		this.pack();
		this.setVisible(true);
	}
 
	/********************************************************************************************* */
 
	/**
         * Main class
         * 
         * @param args
         */
	public static void main(String[] args) {
		new Test();
	}
}
Merci d'avance pour toute l'aide que vous pourriez m'apporter.

Séb.