1
    JButton btnCalendar = new JButton("Chart",new ImageIcon("new_chart.jpg"));
    btnCalendar.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Chart clicked");
        }
    });
    jToolBar1.add(btnCalendar);
    jToolBar1.addSeparator();

I'm developing a Swing based application in which I want to add JToolBar with images in buttons.But images are not visible in the buttons

kleopatra
  • 51,061
  • 28
  • 99
  • 211
Mukthi
  • 561
  • 4
  • 13
  • 35
  • what changed, compared to your last question: http://stackoverflow.com/questions/7846883/jtoolbar-look-feel-in-swing – kleopatra Oct 21 '11 at 10:00
  • im not getting images in the button of tool bar. – Mukthi Oct 21 '11 at 10:01
  • doesn't answer my question: what _changed_ between the other and this? One implication being: don't start a second thread with the same question if you dont understand the answer to the first :-) Another: maybe it's only the image? check if it is where you expect it (f.i. by showing it on another button/label) – kleopatra Oct 21 '11 at 10:16
  • ya i checked to show the same image on a separate button. It's working but its not working in toolbar button. – Mukthi Oct 21 '11 at 10:22
  • still no answer to my question :-) Anyway, it's time for an sscce – kleopatra Oct 21 '11 at 10:57

1 Answers1

0

I face same problem and I resolved by use of following code :

ImageIcon newImage= new ImageIcon(getClass().getResource("com/some/package/newItemImage.jpg"));
JButton newButton= new JButton(newImage);
this.add(newButton);
Roman C
  • 49,761
  • 33
  • 66
  • 176
Kanav
  • 1